Welcome to the bar!
We recommend you drink 1 glass of water per drink so you're not hungover tomorrow morning. Your fellow coders have bought you several drinks tonight in the form of strings. Return a string suggesting how many glasses of water you should drink to not be hungover.
If you would like to keep things simple, you can consider any "numbered thing" in the string to be a drink. Even "1 bear" => "1 glass of water" or "1 chainsaw and 2 pools" => "3 glasses of water".
Example Pairs
Input 0:
"1 beer"
Output 0:
"1 glass of water"
Input 1:
"1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer"
Output 1:
"10 glasses of water"
Tests
hydrate("1 beer")
hydrate("2 glasses of wine and 1 shot")
hydrate("1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer")
Good luck!
This challenge comes from taylormb on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (18)
Python solution
I want to suggest a challenge. What should be the subject of my email? Can I send a markdown file?
Hey Vidit, I'm happy to hear you wanna suggest a challenge. You can send any suggestions to yo+challenge@dev.to. Feel free to drop the content of your challenge in the email, markdown file works too. Subject doesn't matter too much, we'll know what it is.
Take care!
Thanks!
Using regular expressions in JavaScript:
We get the following results:
I didn't see yours, but mine is practically identical 😮
Yours has some checks that make it more robust... And that I probably should add to mine 😳
My solution in python
Python solution 🐍
My swift solution :
Your theme looks amazing, what is it?
What if I drink "11 beers"?
(I have a feeling I'll be severely under-hydrated)
Any chance you would be willing to upload it for me somewhere? :)