mirror of
https://gitlab.com/MisterBiggs/aoc2021.git
synced 2025-06-16 15:06:55 +00:00
day1 done
This commit is contained in:
parent
aa30dfc940
commit
5f1371412f
@ -3,18 +3,19 @@ use std::fs;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let input = fs::read_to_string("../input.txt").expect("Could not read file");
|
let input = fs::read_to_string("../input.txt").expect("Could not read file");
|
||||||
|
|
||||||
let lines: Vec<&str> = input.lines().collect();
|
let lines: Vec<i32> = input.lines().map(|s| s.parse::<i32>().unwrap()).collect();
|
||||||
|
|
||||||
let mut previous: i32 = 10000;
|
let mut previous: i32 = 10000;
|
||||||
let mut increases = 0;
|
let mut increases = 0;
|
||||||
|
|
||||||
for line in lines.iter() {
|
for i in 0..lines.len() - 2 {
|
||||||
let current = line.parse::<i32>().unwrap();
|
let current = lines[i..i + 3].iter().sum();
|
||||||
|
|
||||||
if previous < current {
|
if previous < current {
|
||||||
increases += 1;
|
increases += 1;
|
||||||
}
|
}
|
||||||
previous = current;
|
previous = current;
|
||||||
|
// println!("{}", current);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Increases: {}", increases);
|
println!("Increases: {}", increases);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user