Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The Secret Room solution in Clear category for The Secret Room by JimmyCarlos
# Note: Tiny bit of overkill here, just in case Lord Escher decides he needs another 10**65 rooms.
def small_int_to_words(n) -> str:
"""Turns a number less than 100 into words."""
small_numbers = ["","one","two","three","four","five","six","seven","eight",
"nine","ten","eleven","twelve","thirteen","fourteen","fifteen",
"sixteen","seventeen","eighteen","nineteen","twenty"]
tens = ["zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
if n <= 20: return small_numbers[n]
else: return "{} {}".format(tens[n//10],small_numbers[n%10])
def medium_int_to_words(n) -> str:
"""Turns a number less than 1000 into words."""
hundreds,tensAndUnits = small_int_to_words(n//100),small_int_to_words(n%100)
if hundreds != "" and tensAndUnits != "": return "{} hundred {}".format(hundreds,tensAndUnits)
elif hundreds != "": return "{} hundred".format(hundreds)
else: return "{}".format(tensAndUnits)
def int_to_words(n) -> str:
"""Turns any number into words."""
groupNames = [
"*","thousand","million","billion","trillion","quadrillion","quintillion",
"sextillion","septillion","octillion","nonillion","decillion","undecillion",
"duodecillion","tredecillion","quattuordecillion","quindecillion","sexdecillion",
"septendecillion","octodecillion","novemdecillion","vigintillion"]
numberString = ""
groupIndex = 0
while n != 0:
groupValue = medium_int_to_words(n%1000)
groupName = groupNames[groupIndex]
if groupValue != "":
if groupIndex == 0:
numberString += groupValue
else: numberString = "{} {} {}".format(groupValue,groupName,numberString)
n //= 1000
groupIndex += 1
return numberString
def secret_room(maxDoor):
doors = ["*"] + sorted(int_to_words(n) for n in range(1,maxDoor+1))
return doors.index(int_to_words(maxDoor))
Sept. 15, 2018
Comments: