diff options
author | Federico Igne <git@federicoigne.com> | 2022-06-23 19:06:22 +0100 |
---|---|---|
committer | Federico Igne <git@federicoigne.com> | 2022-06-23 19:06:22 +0100 |
commit | 120d53c0ff20574866ce10fa0538fb8b0dd2ef82 (patch) | |
tree | 4ac370f9b525c713635a6af09530f20758e91fb7 /2021/day1/src/main.rs | |
parent | 5d99706992101d684c9920475e2ecaab65ba21ba (diff) | |
download | aoc-120d53c0ff20574866ce10fa0538fb8b0dd2ef82.tar.gz aoc-120d53c0ff20574866ce10fa0538fb8b0dd2ef82.zip |
Reorganize repository structure
Diffstat (limited to '2021/day1/src/main.rs')
-rw-r--r-- | 2021/day1/src/main.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/2021/day1/src/main.rs b/2021/day1/src/main.rs new file mode 100644 index 0000000..4db292f --- /dev/null +++ b/2021/day1/src/main.rs | |||
@@ -0,0 +1,20 @@ | |||
1 | use std::fs; | ||
2 | |||
3 | fn ex1(sweep: &[u32]) { | ||
4 | let incs = sweep.windows(2).filter(|w| w[0] < w[1]).count(); | ||
5 | println!("Ex1: depth increases {} times.", incs); | ||
6 | } | ||
7 | |||
8 | fn ex2(sweep: &[u32]) { | ||
9 | let incs = sweep.windows(4).filter(|w| w[0] < w[3]).count(); | ||
10 | println!("Ex2: depth increases {} times.", incs); | ||
11 | } | ||
12 | |||
13 | /* AOC21 Day 1: https://adventofcode.com/2021/day/1 */ | ||
14 | fn main() { | ||
15 | let input = "resources/input.txt"; | ||
16 | let content = fs::read_to_string(input).expect("Unable to read input file."); | ||
17 | let sweep: Vec<u32> = content.lines().map(|l| l.parse::<u32>().expect("Malformed input")).collect(); | ||
18 | ex1(&sweep); | ||
19 | ex2(&sweep); | ||
20 | } | ||