diff --git a/2023/day04/src/lib.rs b/2023/day04/src/lib.rs index 57d6310..f3a0284 100644 --- a/2023/day04/src/lib.rs +++ b/2023/day04/src/lib.rs @@ -26,8 +26,29 @@ impl Day for Day04 { } } -fn part1(_input: &str) -> u64 { - 0 +fn part1(input: &str) -> u64 { + input + .lines() + .map(|line| { + let mut numbers = line.split(':').nth(1).unwrap().split("|"); + let winning = numbers + .next() + .unwrap() + .split_whitespace() + .collect::>(); + let you_have = numbers.next().unwrap().split_whitespace(); + + let win_amount = you_have + .filter(|have| winning.iter().any(|w| w == have)) + .count(); + + if win_amount > 0 { + 1 << (win_amount - 1) + } else { + 0 + } + }) + .sum() } fn part2(_input: &str) -> u64 { @@ -37,8 +58,8 @@ fn part2(_input: &str) -> u64 { helper::tests! { day04 Day04; part1 { - small => 0; - default => 0; + small => 13; + default => 24733; } part2 { small => 0;