summaryrefslogtreecommitdiff
path: root/src/bin/day_1.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/day_1.rs')
-rw-r--r--src/bin/day_1.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/bin/day_1.rs b/src/bin/day_1.rs
index 7c9cdbf..9f54c70 100644
--- a/src/bin/day_1.rs
+++ b/src/bin/day_1.rs
@@ -4,15 +4,34 @@ use advent_of_code_2018::*;
use std::error::Error;
use std::path::PathBuf;
+use std::collections::HashSet;
+
// cargo watch -cs "cargo run --bin day_1"
fn main() -> Result<(), Box<Error>> {
let input = read_file(&PathBuf::from("inputs/1.txt"))?;
-
- println!("Input: {:?}", input);
-
-
-
+ let input_ints: Vec<i32> = input.iter().map(|str| str.parse::<i32>().unwrap()).collect();
+
+ println!("Input: {:?}", input_ints);
+
+ let sum: i32 = input_ints.iter().sum();
+ println!("Sum: {}", sum);
+
+ let mut seen = HashSet::new();
+ let mut acc = 0;
+ let mut repeat_found = false;
+ while !repeat_found {
+ for i in &input_ints {
+ if seen.contains(&acc) {
+ repeat_found = true;
+ break;
+ } else {
+ seen.insert(acc);
+ }
+ acc += i;
+ }
+ }
+ println!("First repeat: {}", acc);
Ok(())
}