initial commit
This commit is contained in:
commit
658f3bfca5
31 changed files with 7570 additions and 0 deletions
20
2021/src/bin/01-sonar-sweep.rs
Normal file
20
2021/src/bin/01-sonar-sweep.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
#![allow(dead_code, unused_imports)]
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
use std::{io::{stdin, Read}, str::FromStr};
|
||||
|
||||
fn descending_window(size: usize) -> Result<usize> {
|
||||
Ok(aoc::read_one_per_line::<u32>("./data/1.depths")?
|
||||
.windows(size)
|
||||
.filter(|win| win[0] < win[size - 1])
|
||||
.collect_vec()
|
||||
.len())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
println!("Part 1: {}", descending_window(2)?);
|
||||
println!("Part 2: {}", descending_window(4)?);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue