From ae545e2c8c484b08df7fe2d1d20eda04b2c51000 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Sun, 22 Jan 2023 17:59:32 +0100 Subject: [PATCH] Add initial version The software provides the delta distribution function implementation. --- src/main.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main.rs 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); + +} -- 2.39.2