Skip to content

Instantly share code, notes, and snippets.

@dmadisetti
Created June 13, 2013 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmadisetti/5770850 to your computer and use it in GitHub Desktop.
Save dmadisetti/5770850 to your computer and use it in GitHub Desktop.
Quick hack to verify this rage comic http://wheresmysammich.com/images/34082.jpg for numbers 0-100000. Counter intuitive at first glance but makes sense on closer look
to20 = [
'zero'
,'one'
,'two'
,'three'
,'four'
,'five'
,'six'
,'seven'
,'eight'
,'nine'
,'ten'
,'eleven'
,'twelve'
,'thirteen'
,'fourteen'
,'fifteen'
,'sixteen'
,'seventeen'
,'eighteen'
,'nineteen'
]
by10s = ['twenty'
,'thirty'
,'forty'
,'fifty'
,'sixty'
,'seventy'
,'eighty'
,'ninety'
]
by10powers = [
'hundred'
,'thousand'
]
def cosmetize(number):
# the number is too damn high!
if number >= 100000:
return "Too high"
numstr = str(number)
# Do ones
if number < 10:
return to20[number]
# Pshh.. who needs zero anymore?
to20[0] = ''
# Do tens
numstr10 = numstr[-2:]
if int(numstr10) < 20:
numstr10 = to20[int(numstr10)]
else:
numstr10 = by10s[int(numstr10[0])-2] + to20[int(numstr10[1])]
if number < 100:
return numstr10
# Do hundreds
numstr100 = numstr[-3]
if numstr10 == '':
numstr10 = ""
numstr100 = to20[int(numstr100)] + by10powers[0]
elif int(numstr[-2:]) > 19:
numstr100 = to20[int(numstr100)] + by10powers[0]
numstr100 += 'and'
else:
numstr100 = 'and'
if number < 1000:
return numstr100 + numstr10
# Do thousands
numstr1000 = numstr[:-3]
if numstr100 == 'hundred':
numstr100 = ""
if int(numstr1000) < 20:
numstr1000 = to20[int(numstr1000)] + by10powers[1]
else:
numstr1000 = by10s[int(numstr1000[0])-2] + by10powers[1]
return numstr1000 + numstr100 + numstr10
i = 0
mx = []
z = 0
while i < 100000:
length = cosmetize(i)
x = [length]
while not len(length) == 4:
length = cosmetize(len(length))
i += 1
# No inifinite loop? what magic is this?
print "OMG"
@dmadisetti
Copy link
Author

So much potential for refactor, so little care

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment