diff options
Diffstat (limited to 'rust')
-rw-r--r-- | rust/assembly-line/src/lib.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/rust/assembly-line/src/lib.rs b/rust/assembly-line/src/lib.rs index 4d8d248..287172b 100644 --- a/rust/assembly-line/src/lib.rs +++ b/rust/assembly-line/src/lib.rs @@ -1,14 +1,16 @@ -const CARS_PER_HR: u32 = 221; - -pub fn production_rate_per_hour(speed: u8) -> f64 { - let mut cars: f64 = ((speed as u32) * CARS_PER_HR) as f64; +const CARS_PER_HR: f64 = 221.0; +fn success_rate(speed: u8) -> f64 { match speed { - 5..=8 => cars *= 0.90, - 9 | 10 => cars *= 0.77, - _ => {}, + 1..=4 => 1.0, + 5..=8 => 0.9, + 9|10 => 0.77, + _ => 0.0, } - cars +} + +pub fn production_rate_per_hour(speed: u8) -> f64 { + (speed as f64) * CARS_PER_HR * success_rate(speed) } pub fn working_items_per_minute(speed: u8) -> u32 { |