DEV Community

Discussion on: Daily Challenge #223 - Responsible Drinking

Collapse
 
vidit1999 profile image
Vidit Sarkar

Python solution

import re

def hydrate(drinks: str) -> str:
    drinkCount = sum(map(int, re.findall("\d+", drinks))) # total number of drinks
    # this will also work, drinkCount = sum([int(num) for num in drinks.split(" ") if num.isdigit()])

    return str(drinkCount) + " glass" + ("es" if drinkCount > 1 else "") + " of water"


print(hydrate("1 beer")) # output -> 1 glass of water
print(hydrate("2 glasses of wine and 1 shot")) # output -> 3 glasses of water
print(hydrate("1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer")) # output -> 10 glasses of water
Collapse
 
vidit1999 profile image
Vidit Sarkar

I want to suggest a challenge. What should be the subject of my email? Can I send a markdown file?

Collapse
 
devencourt profile image
Brian Bethencourt

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!

Thread Thread
 
vidit1999 profile image
Vidit Sarkar

Thanks!