Last active
June 26, 2022 02:15
-
-
Save erikyuzwa/66e993a5784a217d092c07e99594b96b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# 1 pound = 0.453 kg | |
def pounds_to_kg(pounds = 0.00) | |
if (pounds < 1.0) | |
0.00 | |
else | |
(pounds / 2.205).round(2) | |
end | |
end | |
# weight given in kg | |
# return lean body mass and fat mass | |
def lbm_and_fat_mass(bodyfat, bodyweight) | |
fm = (bodyfat / 100.00) * bodyweight | |
lbm = bodyweight - fm | |
[lbm, fm] | |
end | |
# calculating your bmr - basal metabolic rate | |
def bmr_muller_method(gender, lbm, fm, age) | |
part1 = 13.587 * lbm | |
part2 = 9.613 * fm | |
part3 = 198 | |
if gender == "f" | |
part3 = 0 | |
end | |
part4 = 3.351 * age | |
part1 + part2 + part3 - part4 + 674.0 | |
end | |
# male or female (m or f) | |
gender = "m" | |
# age | |
age = 0 | |
# weight in pounds | |
weight = 0.0 | |
# bodyfat in percentage amount eg. 23.4 | |
bodyfat = 0.0 | |
# 1.2 baseline | |
# 1.375 light | |
# 1.55 moderate | |
# 1.725 heavy | |
# 1.9 extreme | |
activity_multiplier = 1.2 | |
puts "Welcome to the Keto Macro Calculator" | |
puts "(Using the Muller Method)" | |
puts "" | |
print "Enter gender (m/f): " | |
gender = gets.chomp | |
print "Enter age: " | |
age = gets.chomp.to_i | |
print "Enter weight (lbs.): " | |
weight = gets.chomp.to_i | |
print "Enter bodyfat (%): " | |
bodyfat = gets.chomp.to_i | |
print "Enter activity multiplier (1.2/1.375/1.55/1.75/1.99): " | |
activity_multiplier = gets.chomp.to_i | |
weight_kg = 0.0 | |
bodyfat_kg = 0.0 | |
lbm_kg = 0.0 | |
fat_mass_kg = 0.0 | |
bmr = 0.0 | |
tdee = 0.0 | |
weight_kg = pounds_to_kg(weight) | |
puts "Bodyweight (in kg.): #{weight_kg}" | |
lbm_kg, fat_mass_kg = lbm_and_fat_mass(bodyfat, weight_kg) | |
puts "LBM (in kg.): #{lbm_kg}" | |
puts "Fat Mass (in kg.): #{fat_mass_kg}" | |
bmr = bmr_muller_method(gender, lbm_kg, fat_mass_kg, age) | |
puts "BMR: #{bmr}" | |
tdee = bmr * activity_multiplier | |
puts "Current Total Daily Energy Expenditure (TDEE): #{tdee}" | |
puts "" | |
puts "" | |
puts "Target TDEE values" | |
puts "==================" | |
puts "" | |
# now display a list of surplus and reductions | |
# +15, +10, +5, 0, -5, -10, -15 | |
range = [15, 10, 5, 0, -5, -10, -15] | |
range.each do |n| | |
stage = "Maintenance Phase" | |
if n < 0 | |
result = tdee - ((n.abs / 100.0) * tdee) | |
stage = "Cutting Phase" | |
elsif n > 0 | |
result = tdee + ((n.abs / 100.0) * tdee) | |
stage = "Gain Phase" | |
else | |
result = tdee | |
end | |
puts "Target TDEE (#{n}%)" | |
puts "Type: #{stage}" | |
puts "#{result.round(3)} calories per day" | |
puts "fat (80%): #{(result * 0.80).round(2)} cals or #{((result * 0.80) / 9.0).round(2)} grams" | |
puts "protein (18%): #{(result * 0.18).round(2)} cals or #{((result * 0.18) / 4.0).round(2)} grams" | |
puts "carbs (2%): #{(result * 0.02).round(2)} cals or #{((result * 0.02) / 4.0).round(2)} grams" | |
puts "" | |
end | |
puts "" | |
puts "" |
Author
erikyuzwa
commented
Jun 26, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment