This commit is contained in:
nora 2023-12-04 19:49:27 +01:00
parent 2c1c4ff478
commit 672f2a3674

View file

@ -26,8 +26,29 @@ impl Day for Day04 {
} }
} }
fn part1(_input: &str) -> u64 { fn part1(input: &str) -> u64 {
0 input
.lines()
.map(|line| {
let mut numbers = line.split(':').nth(1).unwrap().split("|");
let winning = numbers
.next()
.unwrap()
.split_whitespace()
.collect::<Vec<_>>();
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 { fn part2(_input: &str) -> u64 {
@ -37,8 +58,8 @@ fn part2(_input: &str) -> u64 {
helper::tests! { helper::tests! {
day04 Day04; day04 Day04;
part1 { part1 {
small => 0; small => 13;
default => 0; default => 24733;
} }
part2 { part2 {
small => 0; small => 0;