extern crate advent_of_code_2018; use advent_of_code_2018::*; extern crate im_rc; use std::error::Error; use std::path::PathBuf; use im_rc::HashSet; // cargo watch -cs "cargo run --release --bin day_1" fn main() -> Result<(), Box> { let input = read_file(&PathBuf::from("inputs/1.txt"))?; let input_ints: Vec = input.iter().map(|str| str.parse::().unwrap()).collect(); println!("Input: {:?}", input_ints); let sum: i32 = input_ints.iter().sum(); println!("Sum: {}", sum); let first_repeat = input_ints.iter().cycle().try_fold((0, HashSet::new()), |(acc, seen), &i| { if seen.contains(&acc) { Err(acc) } else { Ok((acc + i, seen.update(acc))) } }).err().unwrap(); println!("First repeat: {}", first_repeat); Ok(()) }