From cb876e7427a1a4e64c5bdf31095aa941f1e5684b Mon Sep 17 00:00:00 2001 From: jbb01 <32650546+jbb01@users.noreply.github.com> Date: Tue, 16 Sep 2025 20:54:06 +0200 Subject: [PATCH] [08_revisit_everything] fully automate the button --- src/bin/main.rs | 63 +++++++++++++-------- src/lib/challenges/c8_revisit_everything.rs | 25 ++++++++ src/lib/challenges/mod.rs | 3 +- 3 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/lib/challenges/c8_revisit_everything.rs diff --git a/src/bin/main.rs b/src/bin/main.rs index 9f5fad8..3089df3 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -9,39 +9,54 @@ fn main() -> ExitCode { eprintln!("Usage: main NAME"); return ExitCode::FAILURE; } + let mut name = args[1].clone(); - let name = args[1].clone(); + loop { + println!("\nAttempting to solve for \"{}\"", &name); - print!("Solving challenge 01_welcome... "); - let (n, x) = lib::challenges::c1_welcome::solve(); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 01_welcome... "); + let (n, x) = lib::challenges::c1_welcome::solve(); + submit_or_fail(&name, n, x.clone()); - print!("Solving challenge 02_these_numbers_are_big... "); - let (n, x) = lib::challenges::c2_these_numbers_are_big::solve(&name); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 02_these_numbers_are_big... "); + let (n, x) = lib::challenges::c2_these_numbers_are_big::solve(&name); + submit_or_fail(&name, n, x.clone()); - print!("Solving challenge 03_are_you_still_doing_this_by_hand... "); - let (n, x) = lib::challenges::c3_are_you_still_doing_this_by_hand::solve(n, x); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 03_are_you_still_doing_this_by_hand... "); + let (n, x) = lib::challenges::c3_are_you_still_doing_this_by_hand::solve(n, x); + submit_or_fail(&name, n, x.clone()); - print!("Solving challenge 04_broken_proof_of_work... "); - let (n, x) = lib::challenges::c4_broken_proof_of_work::solve(n, x); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 04_broken_proof_of_work... "); + let (n, x) = lib::challenges::c4_broken_proof_of_work::solve(n, x); + submit_or_fail(&name, n, x.clone()); - print!("Solving challenge 05_what_the_bf... "); - let (n, x) = lib::challenges::c5_what_the_bf::solve(n, x); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 05_what_the_bf... "); + let (n, x) = lib::challenges::c5_what_the_bf::solve(n, x); + submit_or_fail(&name, n, x.clone()); - print!("Solving challenge 06_automation_is_not_enough... "); - let (n, x) = lib::challenges::c6_automation_is_not_enough::solve(n, x); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 06_automation_is_not_enough... "); + let (n, x) = lib::challenges::c6_automation_is_not_enough::solve(n, x); + submit_or_fail(&name, n, x.clone()); - print!("Solving challenge 07_weird_assembly_machine... "); - let (n, x) = lib::challenges::c7_weird_assembly_machine::solve(n, x); - submit_or_fail(&name, n, x.clone()); + print!("Solving challenge 07_weird_assembly_machine... "); + let (n, x) = lib::challenges::c7_weird_assembly_machine::solve(n, x); + submit_or_fail(&name, n, x.clone()); - println!("n = {n}"); - println!("x = {x}"); + print!("Solving challenge 08_revisit_everything... "); + let (n, x) = match lib::challenges::c8_revisit_everything::solve(n, x) { + Ok(res) => res, + Err(w) => { + println!("Failed. (w = {})", w); + name.insert_str(0, " "); + continue; + } + }; + submit_or_fail(&name, n, x.clone()); + + println!("n = {}", n); + println!("x = {}", x); + break; + } ExitCode::SUCCESS } diff --git a/src/lib/challenges/c8_revisit_everything.rs b/src/lib/challenges/c8_revisit_everything.rs new file mode 100644 index 0000000..91071b5 --- /dev/null +++ b/src/lib/challenges/c8_revisit_everything.rs @@ -0,0 +1,25 @@ +use rug::ops::DivRounding; +use rug::Integer; +use std::str::FromStr; +use std::sync::LazyLock; + +static PHI: LazyLock = LazyLock::new(|| Integer::from_str("4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616565666555545842363207724851343853529903674824524238732001458342230627654145983386115997227846421784693186847971068054052064").unwrap()); +static M: LazyLock = LazyLock::new(|| Integer::from_str("4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616569935833357648393898915677206732580748330214938398411668157941515847730087263301030154072458063812554524260405671629754999").unwrap()); +static E: LazyLock = LazyLock::new(|| Integer::from(65537)); +static TRUTH: LazyLock = LazyLock::new(|| Integer::from(42)); +const LIMIT: u128 = 100_000_000_000_000_000_000; + +pub fn solve(n: u64, x: Integer) -> Result<(u128, Integer), u32> { + let k = Integer::from(LIMIT - n as u128) * 100; + let e = E.clone().pow_mod(&k, &PHI).unwrap(); + let w: u32 = x.clone().modulo(&TRUTH).try_into().unwrap(); + if w != 30 { + return Err(w); + } + + let mut y = x.clone().div_floor(&*TRUTH); + y = y.pow_mod(&e, &M).unwrap(); + + let x: Integer = y * 42 + w; + Ok((LIMIT, x)) +} \ No newline at end of file diff --git a/src/lib/challenges/mod.rs b/src/lib/challenges/mod.rs index 316df95..916cf5a 100644 --- a/src/lib/challenges/mod.rs +++ b/src/lib/challenges/mod.rs @@ -4,4 +4,5 @@ pub mod c3_are_you_still_doing_this_by_hand; pub mod c4_broken_proof_of_work; pub mod c5_what_the_bf; pub mod c6_automation_is_not_enough; -pub mod c7_weird_assembly_machine; \ No newline at end of file +pub mod c7_weird_assembly_machine; +pub mod c8_revisit_everything; \ No newline at end of file