This commit is contained in:
Shadowfacts 2021-12-01 00:19:46 -05:00
parent 2109ac28d2
commit df0aed7057
4 changed files with 2053 additions and 1 deletions

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aoc21"
version = "0.1.0"

2000
input/day1.txt Normal file

File diff suppressed because it is too large Load Diff

43
src/day1.rs Normal file
View File

@ -0,0 +1,43 @@
pub fn day1() {
// let input = r#"199
// 200
// 208
// 210
// 200
// 207
// 240
// 269
// 260
// 263"#;
let input = include_str!("../input/day1.txt");
let ints = input
.trim()
.lines()
.map(|s| s.trim().parse::<i32>().unwrap());
let mut iter = ints.clone();
let mut prev: i32 = iter.next().unwrap();
let mut count = 0;
for cur in iter {
if cur > prev {
count += 1;
}
prev = cur;
}
println!("count: {}", count);
let mut iter = ints.clone().zip(ints.clone().skip(1).zip(ints.skip(2)));
let first = iter.next().unwrap();
let mut prev_sum = first.0 + first.1 .0 + first.1 .1;
let mut new_count = 0;
for (a, (b, c)) in iter {
let sum = a + b + c;
if sum > prev_sum {
new_count += 1;
}
prev_sum = sum;
}
println!("new_count: {}", new_count);
}

View File

@ -1,3 +1,5 @@
mod day1;
fn main() {
println!("Hello, world!");
day1::day1();
}