[08_revisit_everything] fully automate the button
This commit is contained in:
@@ -9,39 +9,54 @@ 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();
|
||||||
submit_or_fail(&name, n, x.clone());
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
print!("Solving challenge 02_these_numbers_are_big... ");
|
print!("Solving challenge 02_these_numbers_are_big... ");
|
||||||
let (n, x) = lib::challenges::c2_these_numbers_are_big::solve(&name);
|
let (n, x) = lib::challenges::c2_these_numbers_are_big::solve(&name);
|
||||||
submit_or_fail(&name, n, x.clone());
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
print!("Solving challenge 03_are_you_still_doing_this_by_hand... ");
|
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);
|
let (n, x) = lib::challenges::c3_are_you_still_doing_this_by_hand::solve(n, x);
|
||||||
submit_or_fail(&name, n, x.clone());
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
print!("Solving challenge 04_broken_proof_of_work... ");
|
print!("Solving challenge 04_broken_proof_of_work... ");
|
||||||
let (n, x) = lib::challenges::c4_broken_proof_of_work::solve(n, x);
|
let (n, x) = lib::challenges::c4_broken_proof_of_work::solve(n, x);
|
||||||
submit_or_fail(&name, n, x.clone());
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
print!("Solving challenge 05_what_the_bf... ");
|
print!("Solving challenge 05_what_the_bf... ");
|
||||||
let (n, x) = lib::challenges::c5_what_the_bf::solve(n, x);
|
let (n, x) = lib::challenges::c5_what_the_bf::solve(n, x);
|
||||||
submit_or_fail(&name, n, x.clone());
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
print!("Solving challenge 06_automation_is_not_enough... ");
|
print!("Solving challenge 06_automation_is_not_enough... ");
|
||||||
let (n, x) = lib::challenges::c6_automation_is_not_enough::solve(n, x);
|
let (n, x) = lib::challenges::c6_automation_is_not_enough::solve(n, x);
|
||||||
submit_or_fail(&name, n, x.clone());
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
print!("Solving challenge 07_weird_assembly_machine... ");
|
print!("Solving challenge 07_weird_assembly_machine... ");
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/lib/challenges/c8_revisit_everything.rs
Normal file
25
src/lib/challenges/c8_revisit_everything.rs
Normal 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))
|
||||||
|
}
|
||||||
@@ -4,4 +4,5 @@ pub mod c3_are_you_still_doing_this_by_hand;
|
|||||||
pub mod c4_broken_proof_of_work;
|
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;
|
||||||
Reference in New Issue
Block a user