1
0
Fork 0
This commit is contained in:
Lars Martens 2021-12-01 13:29:00 +01:00
commit 8350d5d70b
5 changed files with 2051 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
Cargo.lock

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "aoc2021"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

2000
input/01a.txt Normal file

File diff suppressed because it is too large Load diff

33
src/bin/01.rs Normal file
View file

@ -0,0 +1,33 @@
const INPUT: &str = include_str!("../../input/01a.txt");
fn main() {
let nums = input();
let count = count_increases(nums);
println!("First solution: {}", count);
let input: Vec<i32> = input().collect();
let nums = input.windows(3).map(|w| w.iter().sum());
let count = count_increases(nums);
println!("Second solution: {}", count);
}
fn count_increases(it: impl Iterator<Item = i32>) -> usize {
let mut count = 0;
let mut prev = None;
for n in it {
if let Some(prev) = prev {
if n > prev {
count += 1;
}
}
prev = Some(n);
}
count
}
fn input() -> impl Iterator<Item = i32> {
INPUT.lines().map(|l| l.parse::<i32>().unwrap())
}

8
src/lib.rs Normal file
View file

@ -0,0 +1,8 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}