[08_revisit_everything] fully automate the button

This commit is contained in:
2025-09-16 20:54:06 +02:00
parent 5e37cfe883
commit cb876e7427
3 changed files with 66 additions and 25 deletions

View File

@@ -9,8 +9,10 @@ fn main() -> ExitCode {
eprintln!("Usage: main NAME"); eprintln!("Usage: main NAME");
return ExitCode::FAILURE; 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... "); print!("Solving challenge 01_welcome... ");
let (n, x) = lib::challenges::c1_welcome::solve(); let (n, x) = lib::challenges::c1_welcome::solve();
@@ -40,8 +42,21 @@ fn main() -> ExitCode {
let (n, x) = lib::challenges::c7_weird_assembly_machine::solve(n, x); let (n, x) = lib::challenges::c7_weird_assembly_machine::solve(n, x);
submit_or_fail(&name, n, x.clone()); submit_or_fail(&name, n, x.clone());
println!("n = {n}"); print!("Solving challenge 08_revisit_everything... ");
println!("x = {x}"); 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 ExitCode::SUCCESS
} }

View File

@@ -0,0 +1,25 @@
use rug::ops::DivRounding;
use rug::Integer;
use std::str::FromStr;
use std::sync::LazyLock;
static PHI: LazyLock<Integer> = LazyLock::new(|| Integer::from_str("4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616565666555545842363207724851343853529903674824524238732001458342230627654145983386115997227846421784693186847971068054052064").unwrap());
static M: LazyLock<Integer> = LazyLock::new(|| Integer::from_str("4556683258594822402855414380362620295231673046713752880933967889771646856051745784462468117575177892006513392693685616569935833357648393898915677206732580748330214938398411668157941515847730087263301030154072458063812554524260405671629754999").unwrap());
static E: LazyLock<Integer> = LazyLock::new(|| Integer::from(65537));
static TRUTH: LazyLock<Integer> = 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))
}

View File

@@ -5,3 +5,4 @@ pub mod c4_broken_proof_of_work;
pub mod c5_what_the_bf; pub mod c5_what_the_bf;
pub mod c6_automation_is_not_enough; pub mod c6_automation_is_not_enough;
pub mod c7_weird_assembly_machine; pub mod c7_weird_assembly_machine;
pub mod c8_revisit_everything;