diff --git a/2018/aoc01/src/main.rs b/2018/aoc01/src/main.rs index 8f188f2..5af08f6 100644 --- a/2018/aoc01/src/main.rs +++ b/2018/aoc01/src/main.rs @@ -14,29 +14,29 @@ fn main() -> Result<()> { .expect("Please provide the path to the input file"), )?; - part1(&input); - part2(&input); + println!("part 1: {}", part1(&input)?); + println!("part 2: {}", part2(&input)?); Ok(()) } -fn part1(input: &str) { +fn part1(input: &str) -> Result { let freq = input .lines() .map(|line| line.parse::().unwrap()) .sum::(); - println!("{}", freq); + Ok(freq) } -fn part2(input: &str) { +fn part2(input: &str) -> Result { let mut freqs = HashSet::new(); let mut freq = 0; loop { for line in input.lines() { - freq += line.parse::().unwrap(); + freq += line.parse::()?; if freqs.contains(&freq) { println!("{}", freq); - return; + return Ok(freq); } else { freqs.insert(freq); } diff --git a/2018/aoc02/src/main.rs b/2018/aoc02/src/main.rs index 802f59a..2d97726 100644 --- a/2018/aoc02/src/main.rs +++ b/2018/aoc02/src/main.rs @@ -14,12 +14,12 @@ fn main() -> Result<()> { .expect("Please provide the path to the input file"), )?; - part1(&input)?; + println!("part 1: {}", part1(&input)?); Ok(()) } -fn part1(input: &str) -> Result<()> { +fn part1(input: &str) -> Result { let mut twice = 0; let mut thrice = 0; @@ -38,7 +38,5 @@ fn part1(input: &str) -> Result<()> { } } - println!("{}", twice * thrice); - - Ok(()) + Ok(twice * thrice) }