Created
February 16, 2016 16:50
-
-
Save seaneshbaugh/586921389fe56f891bd2 to your computer and use it in GitHub Desktop.
Calculate desired weight based on body fat percentages
This file contains hidden or 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
| 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