Bitsets ftw
#[inline] fn unique(s: &[u8], n: usize) -> bool { s.iter() .fold(0u32, |acc, &c| acc | (1u32.wrapping_shl(c as u32))) .count_ones() == n as u32 } fn solve(inp: &[u8], n: usize) -> usize { if let Some((i, _)) = inp.windows(n).enumerate().find(|(_, win)| unique(win, n)) { i + n } else { unreachable!() } } pub fn part1(inp: &[u8]) -> usize { solve(inp, 14) } pub fn part2(inp: &[u8]) -> usize { solve(inp, 14) }
@wence started
London Fixed Gear and Single-Speed is a community of predominantly fixed gear and single-speed cyclists in and around London, UK.
This site is supported almost exclusively by donations. Please consider donating a small amount regularly.
Bitsets ftw