Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created May 2, 2014 22:56
Show Gist options
  • Select an option

  • Save h2rd/11488199 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/11488199 to your computer and use it in GitHub Desktop.
# http://en.wikipedia.org/wiki/Blood_alcohol_content
# BAC Chart Values
# 0.00 – 0.03% Normal behavior, no impairme nt
# 0.03 – 0.06% Mild euphoria and impairment; decreased inhibitions
# 0.06 – 0.10% Buzzed, euphoric, increased impairment
# 0.10 – 0.20% Drunk, emotional swings, slurred speech, nausea, loss of reaction time and motor control
# 0.20 – 0.30% Confused, nauseated, poor mentation, black out
# 0.30 – 0.40% Possibly unconscious, unarrousable, loss of bladder function, risk of death
# Above 0.40% Unconscious, coma, impaired breathi ng, risk of death
def calculate(gender, weight, drinks, hour)
metabolism, elimination =
case gender
when 'male' then [0.58, 0.015]
when 'female' then [0.49, 0.017]
end
((0.806 * drinks * 1.2) /
(metabolism * weight) -
(elimination * hour)).round(3)
end
puts calculate('male', 80, 3, 2)
puts calculate('female', 70, 2.5, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment