summaryrefslogtreecommitdiff
path: root/2021/day01/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '2021/day01/src/main.rs')
-rw-r--r--2021/day01/src/main.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/2021/day01/src/main.rs b/2021/day01/src/main.rs
new file mode 100644
index 0000000..4db292f
--- /dev/null
+++ b/2021/day01/src/main.rs
@@ -0,0 +1,20 @@
1use std::fs;
2
3fn 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
8fn 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 */
14fn 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}