Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
change -> sorted -> index solution in Clear category for The Secret Room by fed.kz
def change(n):
book = {0: '',
1: 'one', 11: 'eleven', 10: 'ten',
2: 'two', 12: 'twelve', 20: 'twenty',
3: 'three', 13: 'thirteen', 30: 'thirty',
4: 'four', 14: 'fourteen', 40: 'forty',
5: 'five', 15: 'fifteen', 50: 'fifty',
6: 'six', 16: 'sixteen', 60: 'sixty',
7: 'seven', 17: 'seventeen', 70: 'seventy',
8: 'eight', 18: 'eighteen', 80: 'eighty',
9: 'nine', 19: 'nineteen', 90: 'ninety'
}
if n == 1000: return 'one thousand'
hundreds = book[n // 100] + ' hundred'*bool(book[n//100])
tens = book[n%100] if book.get(n%100) else book[(n%100)//10*10]
units = '' if book.get(n%100) else book[n%10]
return ' '.join((hundreds, tens, units)).strip()
secret_room = lambda number: sorted(change(key) for key in range(1, number +1)).index(change(number)) + 1
Sept. 11, 2018
Comments: