Created
April 12, 2019 08:19
-
-
Save FluffierThanThou/a2281f58b992d3dfcd456e9057934b8d to your computer and use it in GitHub Desktop.
everything is four
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
CACHE_LIMIT = 200 | |
POWERS = [ | |
0, | |
1, | |
2, | |
3, | |
6, | |
9, | |
12, | |
15, | |
18, | |
21, | |
24, | |
27, | |
30, | |
33, | |
36, | |
39, | |
42, | |
45, | |
48, | |
51, | |
54, | |
57, | |
60, | |
63, | |
66, | |
69, | |
72, | |
75, | |
78, | |
81, | |
84, | |
87, | |
90, | |
93, | |
96, | |
99, | |
100 | |
] | |
NAMES = [ | |
"", | |
"tig", | |
"honderd", | |
"duizend", | |
"miljoen", | |
"miljard", | |
"biljoen", | |
"biljard", | |
"triljoen", | |
"triljard", | |
"quadriljoen", | |
"quadriljard", | |
"quintiljoen", | |
"quintiljard", | |
"sextiljoen", | |
"sextiljard", | |
"septiljoen", | |
"septiljard", | |
"octiljoen", | |
"octiljard", | |
"noniljoen", | |
"noniljard", | |
"deciljoen", | |
"deciljard", | |
"undeciljoen", | |
"undeciljard", | |
"duodeciljoen", | |
"duodeciljard", | |
"tredeciljoen", | |
"tredeciljard", | |
"quattuordeciljoen", | |
"quattuordeciljard", | |
"quindeciljoen", | |
"quindeciljard", | |
"sedeciljoen", | |
"sedeciljard", | |
"googol" | |
] | |
TENS = [ | |
"", | |
"tien", | |
"twintig", | |
"dertig", | |
"veertig", | |
"vijftig", | |
"zestig", | |
"zeventig", | |
"tachtig", | |
"negentig" | |
] | |
NUMBERS = [ | |
'nul', | |
'een', | |
'twee', | |
'drie', | |
'vier', | |
'vijf', | |
'zes', | |
'zeven', | |
'acht', | |
'negen', | |
'tien', | |
'elf', | |
'twaalf', | |
'dertien', | |
'veertien', | |
'vijftien', | |
'zestien', | |
'zeventien', | |
'achttien', | |
'negentien' | |
] | |
def number_to_string( number, start = True, main = True ): | |
""" | |
Convert numbers to text (Dutch) | |
""" | |
string = "" | |
for i in range(len(POWERS)-1, 0, -1): | |
oom = pow(10,POWERS[i]) | |
if ( number == 0 and not start ): | |
return "" | |
if ( number < 20 ): | |
return( NUMBERS[number] ) | |
if ( number < 100 and number >= 20 ): | |
r = number % 10 | |
if ( r == 0 ): | |
return( TENS[ number // 10 ] ) | |
else: | |
return( number_to_string( r, False, False ) + "en" + TENS[ number // 10 ]) | |
if ( number >= oom ): | |
n = number // oom | |
prefix = '' | |
divider = '' | |
if main: | |
divider = " " | |
if (n > 1): | |
prefix = number_to_string( n, False, False ) | |
return( prefix + NAMES[i] + divider + number_to_string( number % oom, False ) ) | |
cache = dict() | |
def create_chain( number ): | |
""" | |
Starting with the input number, write it out in natural language, then count the number of characters in that, then write that out, etc. | |
Stop when a loop is reached. | |
Return chain of numbers visited | |
""" | |
visited = set() | |
chain = [] | |
while number not in visited: | |
if ( number in cache ): | |
chain.extend( cache[number] ) | |
return ( chain ) | |
visited.add( number ) | |
chain.append( number ) | |
number = len(number_to_string(number)) | |
return ( chain ) | |
def print_chain( chain ): | |
"""pretty-print a chain""" | |
print ( chain[0], len(chain) ) | |
for y in chain: | |
print( "\t", y, number_to_string( y ) ) | |
if len(sys.argv) > 1: | |
print_chain( create_chain( int( sys.argv[1] ) ) ) | |
else: | |
x = 0 | |
best = ( 0, 0, [0] ) | |
while True: | |
chain = create_chain( x ) | |
if x not in cache and x < CACHE_LIMIT: | |
cache[x] = chain | |
if len(chain) > len(best): | |
best = chain | |
print( "\n\n" ) | |
print_chain( chain ) | |
x = x + 1 | |
print( x, number_to_string( x ), " ", end = "\r" ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment