Created
May 20, 2021 18:49
-
-
Save 10maurycy10/15bd265992975b58e274a5b05bf14f97 to your computer and use it in GitHub Desktop.
a small no-dependancy program to count deaths since it was started.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DEATH_RATE_PER_YEAR:f64 = 8.1/1_000.0; //2020-2025 | |
const WORLD_POPULATION:f64 = 7_800_000_000.0; //2020 | |
const SECONDS_IN_YEAR: f64 = 365.25*86400.0; //10000BC-10000CE | |
fn main() { | |
use std::time::Instant; | |
use std::time::Duration; | |
use std::thread::sleep; | |
let death_per_year = DEATH_RATE_PER_YEAR*WORLD_POPULATION; | |
let deaths_per_second = death_per_year/SECONDS_IN_YEAR; | |
let start = Instant::now(); | |
println!("deaths_per_year: {}",death_per_year); | |
println!("seconds_in_year: {}",SECONDS_IN_YEAR); | |
println!("deaths_per_second: {}",deaths_per_second); | |
println!("\n--------------------------------[DEATH COUNTER]--------------------------------\n"); | |
let mut lastdeaths:f64 = 0.0; | |
loop { | |
let seconds_after_start:f64 = (Instant::now().checked_duration_since(start).unwrap().as_micros() as f64)/1000_000.0; | |
let deaths = seconds_after_start*deaths_per_second; | |
let new_deaths = deaths-lastdeaths; | |
if new_deaths>=1.0 { | |
println!("deaths since start: {}",deaths as u64); | |
lastdeaths = deaths; | |
} | |
sleep(Duration::new(0, 100_000_000)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment