add command line parameter for name
This commit is contained in:
@@ -1,40 +1,69 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::process::ExitCode;
|
||||||
use lib::submit_with_name;
|
use lib::submit_with_name;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> ExitCode {
|
||||||
let mut name = String::from("Jonah");
|
let args: Vec<String> = env::args().collect();
|
||||||
|
if args.len() < 2 {
|
||||||
|
eprintln!("Usage: main NAME");
|
||||||
|
return ExitCode::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut name = args[1].clone();
|
||||||
loop {
|
loop {
|
||||||
let name_temp: &str = &name;
|
println!("\nAttempting to solve for \"{}\"", &name);
|
||||||
|
|
||||||
|
print!("Solving challenge 01_welcome... ");
|
||||||
let (n, x) = lib::challenges::c1_welcome::solve();
|
let (n, x) = lib::challenges::c1_welcome::solve();
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x));
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
let (n, x) = lib::challenges::c2_these_numbers_are_big::solve(name_temp);
|
print!("Solving challenge 02_these_numbers_are_big... ");
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x.clone()));
|
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);
|
let (n, x) = lib::challenges::c3_are_you_still_doing_this_by_hand::solve(n, x);
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x.clone()));
|
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);
|
let (n, x) = lib::challenges::c4_broken_proof_of_work::solve(n, x);
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x.clone()));
|
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);
|
let (n, x) = lib::challenges::c5_what_the_bf::solve(n, x);
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x.clone()));
|
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);
|
let (n, x) = lib::challenges::c6_automation_is_not_enough::solve(n, x);
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x.clone()));
|
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);
|
let (n, x) = lib::challenges::c7_weird_assembly_machine::solve(n, x);
|
||||||
println!("n = {:?}\nx = {:?}\n{:?}\n", n, x, submit_with_name(name_temp, n, x.clone()));
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
|
print!("Solving challenge 08_revisit_everything... ");
|
||||||
let (n, x) = match lib::challenges::c8_revisit_everything::solve(n, x) {
|
let (n, x) = match lib::challenges::c8_revisit_everything::solve(n, x) {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
Err(w) => {
|
Err(w) => {
|
||||||
println!("name = \"{name}\"\nw = {w}\n");
|
println!("Failed. (w = {})", w);
|
||||||
name.insert_str(0, " ");
|
name.insert_str(0, " ");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("n = {n:?}\nx = {x:?}\nname = \"{name}\"\n{:?}\n", submit_with_name(name_temp, n, x.clone()));
|
submit_or_fail(&name, n, x.clone());
|
||||||
|
|
||||||
|
println!("n = {}", n);
|
||||||
|
println!("x = {}", x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExitCode::SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
fn submit_or_fail<T1: Display + Send, T2: Display + Send>(name: &str, n: T1, x: T2) {
|
||||||
|
match submit_with_name(name, n, x) {
|
||||||
|
Ok(_) => println!("Success."),
|
||||||
|
Err(err) => println!("Failure: {}", err),
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user