summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-28 23:38:47 +0530
committerAndinus <andinus@nand.sh>2021-09-28 23:38:47 +0530
commit45fab565a31a535324a335fa96df8f010d855b5c (patch)
tree639f48ea7d0108e6ae5b0775da0ffbfbb0df4c37
parent50bf972e9374c0f433b53ed80805ba5cbfb2a924 (diff)
downloadexercism-45fab565a31a535324a335fa96df8f010d855b5c.tar.gz
Rust: Assembly Line: Use a helper function for success rate
-rw-r--r--rust/assembly-line/src/lib.rs18
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 {