summaryrefslogtreecommitdiff
path: root/2023
diff options
context:
space:
mode:
authornekineki <nekineki@nekineki.net>2023-12-04 20:49:35 +0100
committernekineki <nekineki@nekineki.net>2023-12-04 20:49:35 +0100
commitea117b92bbafaebaab58f20dcce2221b301af74c (patch)
treeae488b4613c3d657ae9617f7dc1681d3d6d9c932 /2023
parent81cbc23069bdee7af154057c8b7fd2fae3223bf0 (diff)
mal bl fp day04
Diffstat (limited to '2023')
-rw-r--r--2023/day04.rs28
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);
}