From: Gustav Eek Date: Wed, 25 Jan 2023 06:59:36 +0000 (+0100) Subject: Src. Provide debug output X-Git-Tag: v.0.2~4 X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=8594e84250c9d3bcc317de8221a4d37f76ebb427;p=ranknauto.git Src. Provide debug output --- diff --git a/src/main.rs b/src/main.rs index a3d9697..aa284b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,8 @@ use std::io::prelude::*; // Bring `std::io::BufRead` in scope use statrs::distribution::{Exp, ContinuousCDF}; // Continuous needed for pdf // use statrs::statistics::Distribution; +const DEBUG: bool = false; + fn input() -> Vec { // Consider datastructure some list of strings let stdin = io::stdin(); @@ -35,9 +37,14 @@ fn normalize(mut arg: Vec) -> Vec { fn delta(n: i32) -> Vec { let mut prio: Vec = Vec::new(); 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); + } } + if DEBUG { eprintln!("\x08\x08."); } prio.reverse(); normalize(prio) } @@ -46,11 +53,16 @@ fn exp(n: i32) -> Vec { const RATE: f64 = 1.0; // rate is unessential thanks to normalization let mut prio: Vec = Vec::new(); 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); } + if DEBUG { eprintln!("\x08\x08."); } prio.reverse(); normalize(prio) } @@ -63,9 +75,12 @@ fn main() { let _prio1 = delta(num); let prio2 = exp(num); + if DEBUG { + for l in ranked.iter() { + eprint!("{}, ", l); + } + eprintln!("\x08\x08."); } - eprintln!(""); - eprintln!("That was {} items: {}", num, prio[0]); output(&prio2, &ranked);