Skip to content

Instantly share code, notes, and snippets.

@djones
Created April 19, 2012 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djones/2422136 to your computer and use it in GitHub Desktop.
Save djones/2422136 to your computer and use it in GitHub Desktop.
Does my coffee hydrate or dehydrate me?
# Do you hydrate or dehydrate your body when having a coffee?
# Constants based on references below
MG_OF_CAFFEINE_PER_SHOT = 77 # mg
SHOT_VOLUME = 44 # ml
WATER_PERCENT_IN_MILK = 87 # %
WATER_LOSS_FROM_CAFFEINE = 1.17 # ml/mg
# number_of_shots : standard single shot
# size_of_cup : in ml
# milk_based : true if the body of the cup is mainly milk
def calculate_water_change(number_of_shots, size_of_cup, milk_based)
# How much water gained?
shot_volume = number_of_shots * SHOT_VOLUME
other_volume = size_of_cup - shot_volume
water_gained = if milk_based
other_volume / 100 * WATER_PERCENT_IN_MILK
else
other_volume
end
# How much water lost?
caffeine = MG_OF_CAFFEINE_PER_SHOT * number_of_shots
water_loss_from_caffeine = caffeine * WATER_LOSS_FROM_CAFFEINE
# Conclusion
net_water = water_gained - water_loss_from_caffeine
word = net_water > 0 ? "gain" : "lose"
puts "For each coffee you #{word} #{net_water.abs.to_i}ml of water"
end
# double shot 8oz cappuccino:
calculate_water_change(2, 237, true) #=> lose 93ml
# double shot 12oz black coffee:
calculate_water_change(2, 355, false) #=> gain 86ml
# double shot 12oz latte:
calculate_water_change(2, 355, true) #=> lose 6ml
# Facts:
#
# * Water loss due to caffeine is 0.00117 L/mg of caffeine [1]
# * 77mg of caffeine per 1.5 ounce shot [2]
# * Cow milk is about 87% water [3]
# * 8 US fluid ounces = 236.588237 ml
# * 1.5 US fluid ounces = 44.3602943 ml
#
# References:
#
# 1 "The diuretic effects of alcohol and caffeine and total water intake misclassification." - http://www.ncbi.nlm.nih.gov/pubmed/10204649
# 2 "Espresso" - http://www.energyfiend.com/caffeine-content/espresso
# 3 "Milk Composition Water" - http://classes.ansci.illinois.edu/ansc438/milkcompsynth/milkcomp_water.html
@djones
Copy link
Author

djones commented Apr 19, 2012

Note:

  • It assumes your cup is full to the brim
  • For non-milk based drinks it assumes you're having black coffee and don't add any milk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment