Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
All numbers are equal solution in Uncategorized category for The Best Number Ever by papernode
def checkio():
explanation = '''There is no best number, because all numbers are equal.
If that doesn't make sense to you, go ahead and simplify
this explanation. I am certain you will see my point.'''
articulations = {
0: 'zero',
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',
1000000: 'million',
1000000000: 'billion',
# and beyond... but that's for another time.
}
articulated_numbers = sorted(articulations.keys())
def nearest_lower_number(number, available_numbers):
last_n = available_numbers[0]
for n in available_numbers:
if number < n:
return last_n
last_n = n
#
def articulate(number):
def _articulate(number, use_direct_articulations = True):
articulation = ''
if number < 0:
articulation += 'minus '
number = -number
if use_direct_articulations and number in articulations:
articulation += articulations[number]
elif number <= 20:
articulation += articulations[number]
elif number < 100:
articulation += '{}-{}'.format(articulations[number // 10 * 10], _articulate(number % 10) if number % 10 > 0 else '')
else:
caps = [100, 1000, 1000000, 1000000000, 1000000000000]
for i, cap in enumerate(caps[1:]):
if number < cap:
articulation += '{}-{}{}'.format(_articulate(number // caps[i], False), _articulate(caps[i]), '-{}'.format(_articulate(number % caps[i])) if number % caps[i] > 0 else '')
break
if articulation == '':
return "I'm sorry, but I can't pronounce that number."
else:
return articulation
#
return _articulate(number, False)
#
def simplify(anything):
if isinstance(anything, int):
anything = articulate(anything)
else:
anything = str(anything)
length = len(anything)
articulated_length = articulate(length)
if len(articulated_length) == length:
return length
else:
return simplify(articulated_length)
#
'And the best number ever is...'
return simplify(explanation)
#
March 10, 2013