Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
sum bool solution in Clear category for The Secret Room by Phil15
BELOW_20 = [None, 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen']
TENS = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
def word(nb):
"""Write numbers 1 to 1000 in words (and 0 --> '')."""
if 0 <= nb < 20:
res = [BELOW_20[nb]]
elif 20 <= nb < 100:
tens, below_ten = divmod(nb, 10)
res = [TENS[tens - 2], BELOW_20[below_ten]]
elif 100 <= nb < 1000:
hundreds, below_hundred = divmod(nb, 100)
res = [BELOW_20[hundreds], 'hundred', word(below_hundred)]
else:
res = ['one', 'thousand']
return ' '.join(elem for elem in res if elem) # remove possible None / 0.
secret_room = lambda door: sum(word(nb) < word(door) for nb in range(door))
Sept. 11, 2018
Comments: