From 77bbebd9e8147b482e2dfb5f2f2706a3a6166f7c Mon Sep 17 00:00:00 2001 From: Connor Slade Date: Wed, 6 Dec 2023 00:19:24 -0500 Subject: [PATCH] [2023] Cleanup day 6 --- aoc_2023/src/day_06.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/aoc_2023/src/day_06.rs b/aoc_2023/src/day_06.rs index 38bb5ff..1caf509 100644 --- a/aoc_2023/src/day_06.rs +++ b/aoc_2023/src/day_06.rs @@ -9,20 +9,11 @@ impl Solution for Day06 { fn part_a(&self, input: &str) -> Answer { let races = parse(input); - races - .iter() - .map(|x| x.ways_to_win()) - .fold(1, |a, b| a * b) - .into() + races.iter().map(Race::ways_to_win).product::().into() } fn part_b(&self, input: &str) -> Answer { - let race = Race { - time: 44826981, - distance: 202107611381458, - }; - - race.ways_to_win().into() + parse_b(input).ways_to_win().into() } } @@ -49,8 +40,24 @@ fn parse(input: &str) -> Vec { out } +fn parse_b(input: &str) -> Race { + let mut lines = input.lines(); + let mut parse = || { + lines + .next() + .unwrap() + .split_whitespace() + .skip(1) + .collect::() + }; + Race { + time: parse().parse().unwrap(), + distance: parse().parse().unwrap(), + } +} + impl Race { - fn ways_to_win(&self) -> u32 { + fn ways_to_win(&self) -> u64 { let mut out = 0; for i in 0..self.time {