This commit is contained in:
2026-05-15 21:22:51 -04:00
parent 48dddc616b
commit af9208ef00
2 changed files with 32 additions and 17 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
usage: usage:
``` ```
> solve 41/63 50/60 55/55 43/64 60/66 51/55 48/59 41/63 solve 41/63 50/60 55/55 43/64 60/66 51/55 48/59 41/63
10: [Wood, Grains, String, String, Oil, Meat, Meat, Gem, Gem, Gem] > Wood:1, Grains:1, String:2, Oil:1, Meat:2, Gem:3 (10 total)
``` ```
solves for the least number of materials needed given a priority solves for the least number of materials needed given a priority
@@ -12,7 +12,7 @@ input is just the stats in order shown in wynncraft (limit/max)
dot `.` means it's maxed out already dot `.` means it's maxed out already
``` ```
> priority wood paper grains string oil meat priority wood paper grains string oil meat
``` ```
sets the material priority for solving (what to use and what to try first) sets the material priority for solving (what to use and what to try first)
+29 -14
View File
@@ -1,6 +1,5 @@
mod data; mod data;
mod solve; mod solve;
use std::io::Write;
pub use data::*; pub use data::*;
pub use solve::*; pub use solve::*;
@@ -18,8 +17,6 @@ fn main() {
]; ];
usage(); usage();
print_priority(&priority); print_priority(&priority);
print!("> ");
let _ = std::io::stdout().flush();
let input = std::io::stdin(); let input = std::io::stdin();
for line in input.lines() { for line in input.lines() {
let Ok(line) = line else { let Ok(line) = line else {
@@ -38,8 +35,6 @@ fn main() {
usage(); usage();
} }
} }
print!("> ");
let _ = std::io::stdout().flush();
} }
} }
@@ -88,9 +83,8 @@ fn run_solve(args: &str, priority: &Priority) {
boost: attrs[6], boost: attrs[6],
training: attrs[7], training: attrs[7],
}; };
println!("requirements: {mount:?}"); let mats = solve(mount, priority);
let res = solve(mount, priority); print_mats(&mats);
println!("{}: {res:?}", res.len());
} }
fn run_priority(args: &str, priority: &mut Priority) { fn run_priority(args: &str, priority: &mut Priority) {
@@ -129,9 +123,11 @@ fn run_priority(args: &str, priority: &mut Priority) {
fn print_priority(priority: &Priority) { fn print_priority(priority: &Priority) {
println!("current priority:"); println!("current priority:");
for (i, mat) in priority.iter().enumerate() { print!(" ");
println!(" {}: {mat:?}", i + 1); for mat in &priority[..priority.len() - 1] {
print!("{mat:?} -> ");
} }
println!("{:?}", priority.last().unwrap());
} }
fn validate_priority(priority: &Priority) -> bool { fn validate_priority(priority: &Priority) -> bool {
@@ -145,12 +141,31 @@ fn validate_priority(priority: &Priority) -> bool {
} }
fn usage() { fn usage() {
println!("usage:"); println!("examples:");
println!(" > solve 41/63 50/60 . 43/64 60/66 51/55 48/59 41/63"); println!(" solve 41/63 50/60 . 43/64 60/66 51/55 48/59 41/63");
println!(" > Wood:1, Grains:1, String:2, Oil:1, Meat:2, Gem:3 (10 total)");
println!(" solves for the least number of materials needed given a priority, eg:"); println!(" solves for the least number of materials needed given a priority, eg:");
println!(" 10: [Wood, Grains, String, String, Oil, Meat, Meat, Gem, Gem, Gem]");
println!(" input is just the stats in order shown in wynncraft (limit/max)"); println!(" input is just the stats in order shown in wynncraft (limit/max)");
println!(" dot '.' means it's maxed out already"); println!(" dot '.' means it's maxed out already");
println!(" > priority wood paper grains string oil meat"); println!(" priority wood paper grains string oil meat");
println!(" sets the material priority for solving (what to use and what to try first)"); println!(" sets the material priority for solving (what to use and what to try first)");
} }
fn print_mats(mats: &[Mat]) {
if mats.is_empty() {
return;
}
let mut count = 0;
let mut prev = mats[0];
for &mat in mats {
if mat == prev {
count += 1;
continue;
} else {
print!("{prev:?}:{count}, ");
count = 1;
}
prev = mat;
}
println!("{prev:?}:{count} ({} total)", mats.len());
}