Skip to content

Instantly share code, notes, and snippets.

@justahero
Created September 9, 2024 12:52
Show Gist options
  • Save justahero/3f3374ca9e562edf3543cadb8d64527e to your computer and use it in GitHub Desktop.
Save justahero/3f3374ca9e562edf3543cadb8d64527e to your computer and use it in GitHub Desktop.
Calculate Heart Rate Zones
/// Prints the heart rate zones assuming a 5 zones distribution with
/// simple ranges. Adjust to your liking.
fn print_zones(resting_heart_rate: u16, max_heart_rate: u16) {
let zones = [(50, 60), (60, 70), (70, 80), (80, 90), (90, 100)];
let heart_rate_reserve = max_heart_rate - resting_heart_rate;
for (index, (lower, upper)) in zones.iter().enumerate() {
let lower = resting_heart_rate + heart_rate_reserve * lower / 100;
let upper = resting_heart_rate + heart_rate_reserve * upper / 100;
println!("HRZ {}: {:3}-{:3}", index + 1, lower, upper);
}
}
fn main() {
print_zones(45, 175);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment