fn output(prio: &Vec<f64>, ranked: &Vec<String>) {
for (p, l) in prio.iter().zip(ranked.iter()) {
- println!("{:2.0} %\t{}", p * 100.0, l);
+ println!("{:2.0} %\t{}", p * 100.0, l);
}
}
fn normalize(mut arg: Vec<f64>) -> Vec<f64> {
let mut sum = 0.0;
for v in &arg {
- sum += v;
+ sum += v;
}
for i in 0..arg.len() {
- arg[i] /= sum;
+ arg[i] /= sum;
}
arg
}
const MEAN: f64 = 1.0; // unessential thanks to normalization
if DEBUG { eprint!("Delta: ") }
for i in 1..n + 1 {
- prio.push(MEAN);
- if DEBUG {
- eprint!("i = {}, x = {:.2}; ", i, MEAN);
- }
+ prio.push(MEAN);
+ if DEBUG {
+ eprint!("i = {}, x = {:.2}; ", i, MEAN);
+ }
}
if DEBUG { eprintln!("\x08\x08."); }
prio.reverse();
let dist = Exp::new(RATE).unwrap();
if DEBUG { eprint!("Exp: ") }
for i in 1..n + 1 {
- let f = i as f64 / (n as f64 + 1.0);
- let x = dist.inverse_cdf(f);
- if DEBUG {
- eprint!("i = {}, f = {:.2}, x = {:.2}; ", i, f, x);
- }
- prio.push(x);
+ let f = i as f64 / (n as f64 + 1.0);
+ let x = dist.inverse_cdf(f);
+ if DEBUG {
+ eprint!("i = {}, f = {:.2}, x = {:.2}; ", i, f, x);
+ }
+ prio.push(x);
}
if DEBUG { eprintln!("\x08\x08."); }
prio.reverse();
let prio2 = exp(num);
if DEBUG {
- for l in ranked.iter() {
- eprint!("{}, ", l);
- }
- eprintln!("\x08\x08.");
+ for l in ranked.iter() {
+ eprint!("{}, ", l);
+ }
+ eprintln!("\x08\x08.");
}
output(&prio2, &ranked);