Skip to content

Instantly share code, notes, and snippets.

@seaneshbaugh
Created February 16, 2016 16:50
Show Gist options
  • Select an option

  • Save seaneshbaugh/586921389fe56f891bd2 to your computer and use it in GitHub Desktop.

Select an option

Save seaneshbaugh/586921389fe56f891bd2 to your computer and use it in GitHub Desktop.
Calculate desired weight based on body fat percentages
def desired_weight(current_weight, current_body_fat_percentage, desired_body_fat_percentage)
raise ArgumentError if current_weight < 0
raise ArgumentError if current_body_fat_percentage < 0
raise ArgumentError if current_body_fat_percentage > 100
raise ArgumentError if desired_body_fat_percentage < 0
raise ArgumentError if desired_body_fat_percentage > 100
current_weight = current_weight.to_f
current_body_fat_percentage = current_body_fat_percentage.to_f / 100.0
desired_body_fat_percentage = desired_body_fat_percentage.to_f / 100.0
lean_weight = current_weight - (current_weight * current_body_fat_percentage)
(lean_weight / (1.0 - desired_body_fat_percentage)).round(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment