Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
speech module solution in Clear category for The Secret Room by Sim0000
FIRST_TEN = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
SECOND_TEN = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
OTHER_TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
HUNDRED = "hundred"
THOUSAND = "thousand"
def secret_room(number):
def f(number):
"speech module"
d = list(map(int, reversed(f'{number:04d}')))
n = number % (10 if d[1] > 1 else 20)
r = [FIRST_TEN[d[3] - 1], THOUSAND] * (d[3] > 0)
r += [FIRST_TEN[d[2] - 1], HUNDRED] * (d[2] > 0)
r += [OTHER_TENS[d[1] - 2]] * (d[1] > 1)
r += [(FIRST_TEN + SECOND_TEN)[n - 1]] * (n > 0)
return ' '.join(r)
return sorted(f(i + 1) for i in range(number)).index(f(number)) + 1
if __name__ == '__main__':
print("Example:")
print(secret_room(5))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert secret_room(5) == 1 #five, four, one, three, two
assert secret_room(3) == 2 #one, three, two
assert secret_room(1000) == 551
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 11, 2018
Comments: