From af9208ef003428ebef792de96553240ea58dc9e9 Mon Sep 17 00:00:00 2001 From: iris Date: Fri, 15 May 2026 21:22:51 -0400 Subject: [PATCH] nicities --- readme.md | 6 +++--- src/main.rs | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/readme.md b/readme.md index fdd7d3d..0d33e97 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ usage: ``` -> 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] +solve 41/63 50/60 55/55 43/64 60/66 51/55 48/59 41/63 +> 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 @@ -12,7 +12,7 @@ input is just the stats in order shown in wynncraft (limit/max) 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) diff --git a/src/main.rs b/src/main.rs index 5c1861d..1209374 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ mod data; mod solve; -use std::io::Write; pub use data::*; pub use solve::*; @@ -18,8 +17,6 @@ fn main() { ]; usage(); print_priority(&priority); - print!("> "); - let _ = std::io::stdout().flush(); let input = std::io::stdin(); for line in input.lines() { let Ok(line) = line else { @@ -38,8 +35,6 @@ fn main() { usage(); } } - print!("> "); - let _ = std::io::stdout().flush(); } } @@ -88,9 +83,8 @@ fn run_solve(args: &str, priority: &Priority) { boost: attrs[6], training: attrs[7], }; - println!("requirements: {mount:?}"); - let res = solve(mount, priority); - println!("{}: {res:?}", res.len()); + let mats = solve(mount, priority); + print_mats(&mats); } 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) { println!("current priority:"); - for (i, mat) in priority.iter().enumerate() { - println!(" {}: {mat:?}", i + 1); + print!(" "); + for mat in &priority[..priority.len() - 1] { + print!("{mat:?} -> "); } + println!("{:?}", priority.last().unwrap()); } fn validate_priority(priority: &Priority) -> bool { @@ -145,12 +141,31 @@ fn validate_priority(priority: &Priority) -> bool { } fn usage() { - println!("usage:"); - println!(" > solve 41/63 50/60 . 43/64 60/66 51/55 48/59 41/63"); + println!("examples:"); + 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!(" 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!(" 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)"); } + +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()); +}