heh
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 678c77d..e54f294 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -50,6 +50,21 @@ fn changes(mut x: u32) -> [(u8, i8); 2001] {
})
}
+#[rustfmt::skip]
+// 8051
+fn next2000(n: u32) -> u32 {
+ let n = n as u64;
+ let m = n | n << 24;
+ let r = (m & 0x61a765) ^ (m >> 1 & 0xc2f82d) ^ (m >> 2 & 0x286d53) ^ (m >> 3 & 0x44f679)
+ ^ (m >> 4 & 0x4d6be8) ^ (m >> 5 & 0x118005) ^ (m >> 6 & 0x5f19f2) ^ (m >> 7 & 0xf03667)
+ ^ (m >> 8 & 0xcea653) ^ (m >> 9 & 0xafa201) ^ (m >> 10 & 0xfd0d29) ^ (m >> 11 & 0x949200)
+ ^ (m >> 12 & 0x49a994) ^ (m >> 13 & 0x21673) ^ (m >> 14 & 0xb4c5bf) ^ (m >> 15 & 0x1e0aaf)
+ ^ (m >> 16 & 0x7cab00) ^ (m >> 17 & 0x95ba48) ^ (m >> 18 & 0x49f04c) ^ (m >> 19 & 0x9a8320)
+ ^ (m >> 20 & 0xb69d39) ^ (m >> 21 & 0x6a2085) ^ (m >> 22 & 0xd13c84) ^ (m >> 23 & 0x1c9e15);
+ r as u32
+
+}
+
#[no_mangle]
pub fn run(x: &str) -> impl Display {
let i = x.as_bytes();
@@ -71,13 +86,27 @@ pub fn run(x: &str) -> impl Display {
map.into_iter().r().max().ψ()
}
+use std::simd::prelude::*;
+#[no_mangle]
+pub fn p1(x: &str) -> impl Display {
+ let mut x = x.as_bytes();
+ let mut i = reading::Integer::<u32>::new(&mut x).array_chunks::<8>();
+ i.by_ref()
+ .map(|x| u32x8::from_array(x.map(next2000)))
+ .fold(u32x8::splat(0), |acc, x| acc + x)
+ .cast::<u64>()
+ .reduce_sum()
+ + i.into_remainder()
+ .map_or(0, |x| x.map(next2000).map(|x| x as u64).sum())
+}
+
fn main() {
let s = include_str!("inp.txt");
- println!("{}", unsafe { run(s) });
+ println!("{}", unsafe { p1(s) });
// dbg!(exec(&program, regi));
}
#[bench]
fn benc(b: &mut test::Bencher) {
let i = boxd(include_str!("inp.txt"));
- b.iter(|| unsafe { run(i) });
+ b.iter(|| unsafe { p1(i) });
}