Last active
December 6, 2022 15:58
-
-
Save timvisee/381de14963fd9c492b349c79dffc990d to your computer and use it in GitHub Desktop.
AoC 2022 day06b extra p{1..94}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "day06b" | |
version = "0.1.0" | |
authors = ["Tim Visee <[email protected]>"] | |
edition = "2021" | |
[dependencies] | |
rayon = "1.6" | |
[profile.release] | |
codegen-units = 1 | |
lto = true | |
strip = true | |
panic = "abort" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rayon::prelude::*; | |
const DATA: &[u8; 10_000_000] = include_bytes!("../input_extra.txt"); | |
pub fn main() { | |
println!("{}", (2..=94).into_par_iter().map(p).sum::<usize>() + 1); | |
} | |
#[inline] | |
fn p(n: usize) -> usize { | |
let mut w = 0; | |
'main: loop { | |
let mut seen = 0u128; | |
for i in (1..=n).rev() { | |
let mask = 1 << DATA[w + i]; | |
if seen & mask == mask { | |
w += i; | |
continue 'main; | |
} | |
seen |= mask; | |
} | |
return w + n + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment