mirror of
https://github.com/Noratrieb/advent-of-code.git
synced 2026-01-16 10:35:02 +01:00
d4p1
This commit is contained in:
parent
2c1c4ff478
commit
672f2a3674
1 changed files with 25 additions and 4 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue