diff options
Diffstat (limited to '2023')
| -rw-r--r-- | 2023/day04.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/2023/day04.rs b/2023/day04.rs index 2f29934..caf578b 100644 --- a/2023/day04.rs +++ b/2023/day04.rs @@ -19,21 +19,21 @@ fn main() { let mut copies = vec![1; lines.len()]; for (i, line) in lines.into_iter().enumerate() { - let nows = line.split_whitespace().collect::<Vec<_>>().join(" "); - let (first, rest) = line.split_once(": ").unwrap(); - + let (first, rest) = line.split_once(":").unwrap(); let game_num = first.split_once(" ").unwrap().1; - let (win, actual) = rest.split_once(" | ").unwrap(); - let win = win - .split_whitespace() - .map(|x| x.parse::<u32>().unwrap()) - .collect::<Vec<_>>(); - let actual = actual - .split_whitespace() - .map(|x| x.parse::<u32>().unwrap()) - .collect::<Vec<_>>(); - - let count = actual.iter().filter(|x| win.contains(x)).count(); + let (win, actual) = rest.split_once("|").unwrap(); + + let parse = |a: &str| { + a.split(" ") + .filter_map(|x| x.parse().ok()) + .collect::<Vec<u32>>() + }; + + let count = parse(actual) + .iter() + .filter(|x| parse(win).contains(x)) + .count(); + if count > 0 { res1 += 1 << (count - 1); } |
