blob: 9f54c7085bbdf177b8f99f77b41d491df8c2df48 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
extern crate advent_of_code_2018;
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"))?;
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(())
}
|