From 120d53c0ff20574866ce10fa0538fb8b0dd2ef82 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Thu, 23 Jun 2022 19:06:22 +0100 Subject: Reorganize repository structure --- 2021/day1/src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2021/day1/src/main.rs (limited to '2021/day1/src/main.rs') 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 @@ +use std::fs; + +fn ex1(sweep: &[u32]) { + let incs = sweep.windows(2).filter(|w| w[0] < w[1]).count(); + println!("Ex1: depth increases {} times.", incs); +} + +fn ex2(sweep: &[u32]) { + let incs = sweep.windows(4).filter(|w| w[0] < w[3]).count(); + println!("Ex2: depth increases {} times.", incs); +} + +/* AOC21 Day 1: https://adventofcode.com/2021/day/1 */ +fn main() { + let input = "resources/input.txt"; + let content = fs::read_to_string(input).expect("Unable to read input file."); + let sweep: Vec = content.lines().map(|l| l.parse::().expect("Malformed input")).collect(); + ex1(&sweep); + ex2(&sweep); +} -- cgit v1.2.3