Commit 235bb6b3 authored by Christoph Häfner's avatar Christoph Häfner

Add deodorant-evaporator

parent f08f5bfc
fn evaporator(_content: f64, evap_per_day: i32, threshold: i32) -> i32 {
return (((threshold as f64) / 100.0).ln() / (1.0 - (evap_per_day as f64) / 100.0).ln()).ceil() as i32;
}
fn evaporator(content: f64, evap_per_day: i32, threshold: i32) -> i32 {
let threshold_in_ml: f64 = content * (threshold as f64 / 100.);
let mut content_left: f64 = content;
let mut days: i32 = 1;
loop {
let ml_left = content_left * (evap_per_day as f64 / 100.);
content_left -= ml_left;
if content_left < threshold_in_ml {
break;
} else {
days += 1;
}
}
days
}
#[cfg(test)]
mod tests {
use super::*;
fn dotest(_content: f64, evap_per_day: i32, threshold: i32, exp: i32) -> () {
println!(" content: {:?}", _content);
println!(" evap_per_day: {:?}", evap_per_day);
println!("threshold: {:?}", threshold);
let ans = evaporator(_content, evap_per_day, threshold);
println!(" actual:\n{:?}", ans);
println!("expect:\n{:?}", exp);
println!(" {};", ans == exp);
assert_eq!(ans, exp);
println!("{};", "-");
}
#[test]
fn basic_tests() {
dotest(10.0, 10, 10, 22);
dotest(10.0, 10, 5, 29);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment