It's weekend and what are the cool guys doing on weekends? Drinking of course! But you know what's not so cool? Drinking and driving. So you decide to write a program that tells you how loaded you are and when you are gonna be able to drive again without getting pulled over by the cops and loosing your license.
Given a list of beverages you enjoyed this evening, calculate your blood alcohol level and the time you have to wait till you can hop into your car and get home.
Input will be a list of drinks you had this night. This will look like this:
4 shots booze 1 glasses wine 2 bottles beer 3 glasses water
Containers will always be plural.
As you can see each entry consists of:
- The type of drink (booze, wine, beer, water)
- The container for the drink (shots, glasses, bottles)
- The amount x of the drinks you had of that type as integer with x > 0,
Each drink type adds a certain amount of alcohol to your blood:
booze -> 0.5 ‰ / 100 ml beer -> 0.1 ‰ / 100 ml wine -> 0.2 ‰ / 100 ml water -> -0.1 ‰ / 100 ml
Water is the exception here, since it thins your blood out and lowers your alcohol level (would be so nice if that actually worked...).
Each container has a certain volume:
shots -> 20 ml glasses -> 200 ml bottles -> 500 ml
You have to output two numbers:
- The alcohol level in ‰
- The time in hours you have to wait until you reached 0.5 ‰ or less, so you can drive again. You loose 0.1 ‰ per hour.
- The alcohol level can never fall below zero.
- Same goes for the waiting time. If you have 0.5 ‰ or less, output zero.
- The order of drinks does not matter, so drinking water may lower the alcohol level below zero in the process of the calculation. If it remains there, you need to replace it with zero.
The alcohol level for the the example above would be calculated like this:
4 shots booze -> 0.4 ‰ 1 glasses wine -> 0.4 ‰ 2 bottles beer -> 1.0 ‰ 3 glasses water -> -0.6 ‰ => 0.4 + 0.4 + 1 - 0.6 = 1.2 ‰
To reach 0.5 ‰ you need to loose 0.7 ‰. You loose 0.1 ‰ per hour, so you need to wait 7 hours to drive again.
- You can take the input in any format you want, but you have to use the exact strings as given above. You may take the numbers as integers.
- You can output the two numbers in any order, just make in clear which one you use in your answer.
- You may assume that the input will always have at least one entry.
- Function or full program allowed.
- Default rules for input/output.
- Standard loopholes apply.
- This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.
Input as list of strings. Outputs alcohol level first, values seperated by a comma.
["4 shots booze","1 glasses wine","2 bottles beer","3 glasses water"] -> 1.2, 7 ["10 shots booze", "1 bottle water"] -> 0.5, 0 ["3 glasses wine", "2 bottles booze"] -> 6.2, 57 ["6 shots beer", "3 glasses water"] -> 0, 0 ["10 glasses beer"] -> 2.0, 15