diff --git a/src/main.rs b/src/main.rs index e0400cd..3532ac2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,21 +50,17 @@ fn main() { }).collect_vec(), }; let mut running = vec![true; names.len()]; - let mut first = true; + print!(",,,"); for name in names.iter() { - if first { - first = false; - } - else { - print!(","); - } - print!("{name:?}"); + print!(",{name:?},"); } println!(); eprintln!("Running election rounds:"); let to_percent = |score: f64| score / f64::from(total) * 100.0; + let mut scores_last: Option> = None; + let mut id_worst_last: Option = None; for index in 0..(running.len() - winner_count + 1) { let scores = counter.count_all_with_powers_of_2(ty, &running); @@ -74,32 +70,45 @@ fn main() { None => break, }; - let mut first = true; + if let Some(scores_last) = scores_last { + let id_worst_last = id_worst_last.unwrap(); + let score_worst_last = scores_last[id_worst_last]; + print!(",{:?},{score_worst_last},{:.3}%", names[id_worst_last], to_percent(score_worst_last)); + for ((&score, &score_last), &running) in scores.iter().zip(scores_last.iter()).zip(running.iter()) { + if running { + let score_diff = score - score_last; + print!(",+{score_diff},+{:.3}%", score_diff / score_worst_last * 100.0); + } else { + print!(",,"); + } + } + println!(); + } + print!("{},,,", index + 1); for (&score, &running) in scores.iter().zip(running.iter()) { - if first { - first = false; - } - else { - print!(","); - } if running { - print!("{score}"); + print!(",{score},{:.3}%", to_percent(score)); + } else { + print!(",,"); } } + println!(); running[id_worst] = false; + scores_last = Some(scores); + id_worst_last = Some(id_worst); let mut total_votes = 0.0; println!(); eprintln!("Round {}:", index+1); for (place, &(id, score)) in scores_ordered.iter().take(winner_count).enumerate() { - eprintln!(" {}. {}: {score}, {:.2}%", place + 1, names[id], to_percent(score)); + eprintln!(" {}. {}: {score}, {:.3}%", place + 1, names[id], to_percent(score)); total_votes += score; } if scores_ordered.len() > winner_count { - eprintln!(" {}. {}: {score_worst}, {:.2}%", scores_ordered.len(), names[id_worst], to_percent(score_worst)); + eprintln!(" {}. {}: {score_worst}, {:.3}%", scores_ordered.len(), names[id_worst], to_percent(score_worst)); } - eprintln!(" Total: {total_votes}, {:.2}%", to_percent(total_votes.into())); + eprintln!(" Total: {total_votes}, {:.3}%", to_percent(total_votes.into())); } }