This commit is contained in:
2026-05-15 20:06:19 -04:00
parent 590995f969
commit cdcbbf418c
+7 -6
View File
@@ -14,6 +14,7 @@ fn main() {
Mat::Ingot, Mat::Ingot,
Mat::Gem, Mat::Gem,
]; ];
usage();
print_priority(&priority); print_priority(&priority);
let input = std::io::stdin(); let input = std::io::stdin();
for line in input.lines() { for line in input.lines() {
@@ -21,15 +22,15 @@ fn main() {
println!("error reading line"); println!("error reading line");
continue; continue;
}; };
let Some((cmd, args)) = line.split_once(" ") else { let (cmd, args) = match line.split_once(" ") {
println!("space expected after command"); Some(v) => v,
continue; None => (line.as_str(), ""),
}; };
match cmd { match cmd {
"solve" => run_solve(args, &priority), "solve" => run_solve(args, &priority),
"priority" => run_priority(args, &mut priority), "priority" => run_priority(args, &mut priority),
_ => { _ => {
println!("unknown command"); println!("unknown command {cmd}");
} }
} }
} }
@@ -116,7 +117,7 @@ fn run_priority(args: &str, priority: &mut Priority) {
} }
fn print_priority(priority: &Priority) { fn print_priority(priority: &Priority) {
println!("priority:"); println!("current priority:");
for (i, mat) in priority.iter().enumerate() { for (i, mat) in priority.iter().enumerate() {
println!(" {}: {mat:?}", i + 1); println!(" {}: {mat:?}", i + 1);
} }
@@ -133,7 +134,7 @@ fn validate_priority(priority: &Priority) -> bool {
} }
fn usage() { fn usage() {
println!("Usage:"); println!("usage:");
println!(" > solve 41/63 50/60 55/55 43/64 60/66 51/55 48/59 41/63"); println!(" > solve 41/63 50/60 55/55 43/64 60/66 51/55 48/59 41/63");
println!(" solves for the least number of materials needed given a priority"); println!(" solves for the least number of materials needed given a priority");
println!(" > priority wood paper grains string oil meat"); println!(" > priority wood paper grains string oil meat");