summaryrefslogtreecommitdiff
path: root/2021/day1/src
diff options
context:
space:
mode:
Diffstat (limited to '2021/day1/src')
-rw-r--r--2021/day1/src/main.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/2021/day1/src/main.rs b/2021/day1/src/main.rs
new file mode 100644
index 0000000..7e18b94
--- /dev/null
+++ b/2021/day1/src/main.rs
@@ -0,0 +1,21 @@
+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 1..values.len() {
+ if values[index - 1] < values[index] {
+ increasing += 1;
+ }
+ }
+
+ println!("{}", increasing);
+}