summary refs log tree commit diff stats
path: root/rust/assembly-line/src/lib.rs
blob: 287172b98c014a8b58c453e2180f99743b6a6ec3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const CARS_PER_HR: f64 = 221.0;

fn success_rate(speed: u8) -> f64 {
    match speed {
        1..=4 => 1.0,
        5..=8 => 0.9,
        9|10 => 0.77,
        _ => 0.0,
    }
}

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 {
    (production_rate_per_hour(speed) / 60.0).floor() as u32
}