DEV Community

Discussion on: Daily Challenge #280 - Driving School

Collapse
 
qm3ster profile image
Mihail Malo

Rust

pub fn cost(mut mins: usize) -> usize {
    mins = mins.saturating_sub(5);
    if mins == 0 {
        0
    } else {
        30 + mins.saturating_sub(60) / 30 * 10
    }
}

which produces the same assembly as

pub fn cost(mins: usize) -> usize {
    if mins <= 5 {
        0
    } else {
        30 + mins.saturating_sub(65) / 30 * 10
    }
}