Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Readable: uncompressed lines, meaningful variables and comments solution in Clear category for The Secret Room by kkkkk
NUMBER_TEXT = {
0: '',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
9: 'nine',
10: 'ten',
11: 'eleven',
12: 'twelve',
13: 'thirteen',
14: 'fourteen',
15: 'fifteen',
16: 'sixteen',
17: 'seventeen',
18: 'eighteen',
19: 'nineteen',
20: 'twenty',
30: 'thirty',
40: 'forty',
50: 'fifty',
60: 'sixty',
70: 'seventy',
80: 'eighty',
90: 'ninety',
100: 'hundred',
1000: 'thousand'
}
def text_below_100(number, prefix, text):
"""Append string representation of numbers up to number in text."""
limit_under_20 = number + 1 if number < 20 else 20
for num in range(1, limit_under_20):
text.append(f'{prefix}{NUMBER_TEXT[num]}')
limit_over_20 = number + 1 if number < 100 else 100
for num in range(20, limit_over_20):
modulo = num % 10
if modulo:
text.append(f'{prefix}'
f'{NUMBER_TEXT[num - modulo]}-{NUMBER_TEXT[modulo]}')
else:
text.append(f'{prefix}{NUMBER_TEXT[num - modulo]}')
def secret_room(number):
"""Return the last number after alphabetically sorting 'number' numbers."""
text = []
if number < 100:
text_below_100(number, '', text)
elif number <= 1000:
text_below_100(99, '', text)
text.append(f'{NUMBER_TEXT[1]} {NUMBER_TEXT[100]}')
# Full hundred units.
for hundred_unit in range(1, number // 100):
text_below_100(99,
f'{NUMBER_TEXT[hundred_unit]} {NUMBER_TEXT[100]} ',
text)
text.append(f'{NUMBER_TEXT[hundred_unit + 1]} {NUMBER_TEXT[100]}')
# The remaining portion that is less than a hundred.
modulo = number // 100
text_below_100(number - (modulo * 100),
f'{NUMBER_TEXT[modulo]} {NUMBER_TEXT[100]} ', text)
if number == 1000:
text.append(f'{NUMBER_TEXT[1]} {NUMBER_TEXT[1000]}')
# Find the location of the text for the last number in the sorted list
# of numbers.
last_door_text = text[-1]
for idx, num_text in enumerate(sorted(text)):
if num_text == last_door_text:
break
return idx + 1
Nov. 26, 2019
Comments: