From: Gustav Eek Date: Sun, 22 Jan 2023 16:59:32 +0000 (+0100) Subject: Add initial version X-Git-Tag: v.0.1 X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=ae545e2c8c484b08df7fe2d1d20eda04b2c51000;p=ranknauto.git Add initial version The software provides the delta distribution function implementation. --- diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..949ac53 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +//! Copyright (C) 2023 Gustav Eek +//! +//! SPDX-License-Identifier: GPL-3.0-or-later + +use std::io; // bring flush() into scope with `use std::io::Write` +use std::io::prelude::*; // Bring `std::io::BufRead` in scope + +fn input() -> Vec { + // Consider datastructure some list of strings + let stdin = io::stdin(); + let v = stdin.lock().lines().map(|x| x.unwrap()).collect(); + v +} + +fn output(prio: Vec, ranked: Vec) { + for (p, l) in prio.iter().zip(ranked.iter()) { + println!("{:2.0} %\t{}", p * 100.0, l); + } +} + +fn delta(n: i32) -> Vec { + let mut ret: Vec = Vec::new(); + for _i in 0..n { + ret.push(1.0 / n as f64); + } + ret +} + +fn main() { + let ranked: Vec = input(); + let num = ranked.len() as i32; + let prio = delta(num); + for p in prio.iter() { + eprint!("{} ", p); + } + eprintln!(""); + for l in ranked.iter() { + eprint!("{} ", l); + } + eprintln!(""); + eprintln!("That was {} items: {}", num, prio[0]); + + output(prio, ranked); + +}