diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-12-06 21:04:28 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-12-06 21:33:16 +0100 |
commit | f754fb2b193bfd17a7af51fae32f0805a1f16d0b (patch) | |
tree | 21c72600fe749e882882759341582cc182467a7d /day1/src |
Add day1
Diffstat (limited to 'day1/src')
-rw-r--r-- | day1/src/main.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/day1/src/main.rs b/day1/src/main.rs new file mode 100644 index 0000000..ed6c56c --- /dev/null +++ b/day1/src/main.rs @@ -0,0 +1,25 @@ +use std::fs::File; +use std::io::prelude::*; +use std::io::BufReader; + +fn main() { + let file = File::open("input.txt").expect("File not found"); + let reader = BufReader::new(file); + let values: Vec<i32> = reader + .lines() + .map(|x| x.unwrap().parse::<i32>().unwrap()) + .collect::<Vec<i32>>(); + let mut increasing: u16 = 0; + + for (index, _) in values.iter().enumerate() { + if index == 0 { + continue; + } + + if values[index - 1] < values[index] { + increasing += 1; + } + } + + println!("{}", increasing); +} |