Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Tear them apart! solution in Clear category for The Secret Room by veky
import functools
start = ' one two three four five six seven eight nine ten eleven twelve'
memo = dict(enumerate(start.split(' ')))
@functools.lru_cache(maxsize=len(memo))
def inflect(n):
root = memo[n]
for frm, to in {'o':'en', 'ree':'ir', 've':'f', 't':''}.items():
if root.endswith(frm): root = root[:-len(frm)] + to
return root
@functools.lru_cache(maxsize=1000)
def speak(n):
if n == 1000: return 'one thousand'
hundreds, below = divmod(n, 100)
tens, ones = divmod(below, 10)
big = inflect(tens).replace('u', '') + 'ty ' + memo[ones]
rest = memo.get(below, inflect(ones) + 'teen' if tens < 2 else big)
return (memo[hundreds] + ' hundred ' * bool(hundreds) + rest).strip()
def secret_room(number):
return sum(speak(1 + i) <= speak(number) for i in range(number))
Sept. 14, 2018
Comments: