heh
-rw-r--r--Cargo.toml2
-rw-r--r--beeg-basicbin0 -> 80000000 bytes
-rw-r--r--beeg2-larger-basicbin0 -> 40000000 bytes
-rw-r--r--src/main.rs83
4 files changed, 17 insertions, 68 deletions
diff --git a/Cargo.toml b/Cargo.toml
index eac7a73..a1b3b31 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,4 +17,4 @@ rustc-hash = { version = "2.1.0", features = ["nightly"] }
lto = true
codegen-units = 1
debug = true
-# overflow-checks = true
+overflow-checks = true
diff --git a/beeg-basic b/beeg-basic
new file mode 100644
index 0000000..6e01760
--- /dev/null
+++ b/beeg-basic
Binary files differ
diff --git a/beeg2-larger-basic b/beeg2-larger-basic
new file mode 100644
index 0000000..7b4f47a
--- /dev/null
+++ b/beeg2-larger-basic
Binary files differ
diff --git a/src/main.rs b/src/main.rs
index 38c0cdd..44991c7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -38,75 +38,24 @@ use std::sync::OnceLock;
pub use util::prelude::*;
#[no_mangle]
-pub fn run(i: &str) -> impl Display {
- let i = i.as_bytes();
- let mut input = i.κ::<u64>().collect_vec();
- input.reserve_exact(30000);
- for _ in 0..25 {
- let i = input.clone();
- unsafe { input.set_len(0) };
- for stone in i {
- match stone {
- 0 => input.push(1),
- n if let ͱ = n.ͱ() as usize
- && ͱ % 2 == 0 =>
- {
- let pow = util::powers[ͱ / 2];
- input.push(n % pow);
- input.push(n / pow);
- }
- n => input.push(n * 2024),
- }
- }
- }
- input.len()
+pub unsafe fn p1(i: &str) -> impl Display {
+ let i = i.as_bytes().trim_ascii_end();
+ let mut o = [0u32; 8];
+ const LUT: [u32; 10000000] = unsafe {
+ std::mem::transmute::<[u8; 10000000 * 4], _>(*include_bytes!("../beeg2-larger-basic"))
+ };
+ reading::κ(i, &mut o);
+ o.into_iter().map(|stone| C!{ LUT[stone as usize] }).sum::<u32>()
}
#[no_mangle]
pub unsafe fn p2(i: &str) -> impl Display {
let i = i.as_bytes().trim_ascii_end();
- let mut o = [0u64; 10];
- let n = reading::κ(i, &mut o);
- static mut map: OnceLock<HashMap<(u64, u8), u64>> = OnceLock::new();
- unsafe {
- match map.get_mut() {
- Some(x) => x.clear(),
- None => drop(map.get_or_init(|| {
- HashMap::with_capacity_and_hasher(150000, rustc_hash::FxBuildHasher::default())
- })),
- }
- };
- fn rocc(one: u64, iters: u8) -> u64 {
- if let Some(&x) = unsafe { map.get_mut().ψ().get(&(one, iters)) } {
- return x;
- }
- let answer = {
- match iters.checked_sub(1) {
- Some(iters) if one == 0 => rocc(1, iters),
- Some(iters)
- if let ͱ = one.ͱ() as usize
- && ͱ % 2 == 0 =>
- {
- let pow = util::powers[ͱ / 2];
- rocc(one / pow, iters) + rocc(one % pow, iters)
- }
- Some(iters) if iters > 1 && (one * 2024).ͱ() % 2 == 1 => {
- // skip
- let one = one * 2024 * 2024;
- let pow = util::powers[one.ͱ() as usize / 2];
- rocc(one / pow, iters - 2) + rocc(one % pow, iters - 2)
- }
- Some(iters) => rocc(one * 2024, iters),
- None => 1,
- }
- };
- unsafe { map.get_mut().ψ() }.insert((one, iters), answer);
- answer
- }
- o.into_iter()
- .take(n)
- .map(|stone| rocc(stone, 75))
- .sum::<u64>()
+ let mut o = [0u64; 8];
+ const LUT: [u64; 10000000] =
+ unsafe { std::mem::transmute::<[u8; 10000000 * 8], _>(*include_bytes!("../beeg-basic")) };
+ reading::κ(i, &mut o);
+ o.into_iter().map(|stone| C! { LUT[stone as usize] }).sum::<u64>()
}
fn main() {
@@ -114,10 +63,10 @@ fn main() {
// let mut s = String::new();
// for i in 0..1280 {
let i = include_str!("inp.txt");
- // s.push_str(i);
+ // s.push_str(i);i
// }
// std::fs::write("src/inp.txt", s);
- // println!("{}", p2(i));
+ println!("{}", unsafe { p1(i) });
println!("{}", unsafe { p2(i) });
// println!("{}", p1(i));
}
@@ -125,5 +74,5 @@ fn main() {
#[bench]
fn bench(b: &mut test::Bencher) {
let i = boxd(include_str!("inp.txt"));
- b.iter(|| unsafe { p2(i) });
+ b.iter(|| unsafe { p1(i) });
}