summaryrefslogtreecommitdiff
path: root/2021/day1/src/main.rs
blob: 4db292f32a0100a59e254fa4ec36ea7d55541e61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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<u32> = content.lines().map(|l| l.parse::<u32>().expect("Malformed input")).collect();
    ex1(&sweep);
    ex2(&sweep);
}