From 50bf972e9374c0f433b53ed80805ba5cbfb2a924 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 11 Sep 2021 19:36:29 +0530 Subject: Rust: Assembly Line: Add solution --- rust/assembly-line/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'rust/assembly-line/src') diff --git a/rust/assembly-line/src/lib.rs b/rust/assembly-line/src/lib.rs index de29988..4d8d248 100644 --- a/rust/assembly-line/src/lib.rs +++ b/rust/assembly-line/src/lib.rs @@ -1,11 +1,16 @@ -// This stub file contains items which aren't used yet; feel free to remove this module attribute -// to enable stricter warnings. -#![allow(unused)] +const CARS_PER_HR: u32 = 221; pub fn production_rate_per_hour(speed: u8) -> f64 { - unimplemented!("calculate hourly production rate at speed: {}", speed) + let mut cars: f64 = ((speed as u32) * CARS_PER_HR) as f64; + + match speed { + 5..=8 => cars *= 0.90, + 9 | 10 => cars *= 0.77, + _ => {}, + } + cars } pub fn working_items_per_minute(speed: u8) -> u32 { - unimplemented!("calculate the amount of working items at speed: {}", speed) + (production_rate_per_hour(speed) / 60.0).floor() as u32 } -- cgit 1.4.1-2-gfad0