blob: 328d84a4f1390be56946fd806c126801e8d85004 (
plain) (
tree)
|
|
#![feature(array_chunks)]
#![feature(iter_array_chunks)]
static INPUT: &[u8] = include_bytes!("input.txt");
fn parse_val(s: &[u8]) -> u8 {
(if s[0].is_ascii_digit() { (s[0] - b'0') * 10 } else { 0 }) +
s[1] - b'0'
}
fn main() {
let valueified = INPUT.array_chunks::<117>()
.map(|b| {
let win: u128 = b[10..40].array_chunks::<3>().fold(0, |a, b| a | (1 << parse_val(&b[0..2])));
let val: u128 = b[42..].array_chunks::<3>().fold(0, |a, b| a | (1 << parse_val(&b[0..2])));
(win & val).count_ones()
});
let winsum = valueified.clone().map(|c| if c == 0 { 0 } else { 2u32.pow(c - 1) }).sum::<u32>();
println!("Sum of Win Scores: {winsum}");
let mut nums = valueified.map(|n| (n as usize, 1)).collect::<Vec<(usize, u32)>>();
for i in 0..nums.len() {
let (m, c) = nums[i];
for n in i + 1 .. (i + m + 1).min(nums.len()) {
nums[n].1 += c;
}
}
let cardsum = nums.into_iter().map(|(_, c)| c).sum::<u32>();
println!("Sum of Recursive Card Counting: {cardsum}");
}
|