use std::collections::HashSet; use std::env; use std::fs; type Result = std::result::Result>; fn main() -> Result<()> { let mut args = env::args(); args.next(); let input = fs::read_to_string( &args .next() .expect("Please provide the path to the input file"), )?; part1(&input); part2(&input); Ok(()) } fn part1(input: &str) { let freq = input .lines() .map(|line| line.parse::().unwrap()) .sum::(); println!("{}", freq); } fn part2(input: &str) { let mut freqs = HashSet::new(); let mut freq = 0; loop { for line in input.lines() { freq += line.parse::().unwrap(); if freqs.contains(&freq) { println!("{}", freq); return; } else { freqs.insert(freq); } } } }