Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Naive solution in Clear category for The Secret Room by obone
DIGITS = ['0', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine']
TENS = ['0', '10', 'twenty', 'thirty', 'forty', 'fifty',
'sixty', 'seventy', 'eighty', 'ninety']
DIGITS2 = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
def num2text(number):
text = []
if 999 < number:
text.append('one thousand')
number %= 1000
if 99 < number:
text.append(DIGITS[number // 100])
text.append('hundred')
number %= 100
if 19 < number:
text.append(TENS[number // 10])
number %= 10
if 9 < number:
text.append(DIGITS2[number - 10])
number = 0
if 0 < number:
text.append(DIGITS[number])
number = 0
return ' '.join(text)
def secret_room(number):
nums = [num2text(i + 1) for i in range(number)]
num = nums[-1]
nums.sort()
return nums.index(num) + 1
July 24, 2019