Given an input, calculate the correct suffix and output the number in a readable format in short scale (where 1 billion is 10^9). The suffixes must go to at least 10^3000, in which the rules for calculating them can be found here, or a list can be found here.
There is no need to output the exact numbers, this is focused on getting a huge number into a readable format.
For example:
10000 = 10.0 thousand
135933445 = 135.93 million
-2 = -2.0
-2.36734603 = -2.37
'1'+'9'*3000 = 2.0 nongennovemnonagintillion
// out of range examples
'1'+'9'*3010 = 20000000000.0 nongennovemnonagintillion
'-1'+'9'*5000 = -inf nongennovemnonagintillion
I am aware it is similar to this question, though with 10x as many numbers and not having to read the names, there's potentially a lot more room for golfing. For the record, my result is 578 characters in Python.
Rules:
- No getting things from external resources - it must all be calculated within the code.
- External modules are fine, just don't break the above rule.
- The code should work when input is either a string, integer or float (eg. you may wish to input the super large numbers as strings).
- The output must always contain a decimal place.
- The output must be rounded if above 2 decimal places. Using the inbuilt round function is fine, I am aware there are some floating point errors, so if the occasional '.045' doesn't round up to '.05' for example, don't worry about it.
- Leaving multiple zeroes at the end is optional, as long as it doesn't go above 2 decimals (1.00 or 1.0 are both fine) and is consistent for all inputs (an input of 1 and 1.0 should output the same result).
- An input too large shouldn't cause an error,
inf
is a valid value since it's part offloat
.
Scoring:
- Score is the length of the code, including indents.
- Lowest score wins.
- Output can be either printed or returned.
- Setting the input number does not count towards length.
As a starting point, here is an ungolfed version of some code in Python to generate the list of suffixes. Feel free to build upon this or start from scratch.
a = ['', 'un','duo','tre','quattor','quin','sex','septen','octo','novem']
c = ['tillion', 'decillion', 'vigintillion', 'trigintillion', 'quadragintillion', 'quinquagintillion', 'sexagintillion', 'septuagintillion', 'octogintillion', 'nonagintillion']
d = ['', 'cen', 'duocen', 'trecen', 'quadringen', 'quingen', 'sescen', 'septingen', 'octingen', 'nongen']
num_dict = ['']
num_dict.append('thousand')
num_dict.append('million')
num_dict.append('billion')
num_dict.append('trillion')
num_dict.append('quadrillion')
num_dict.append('quintillion')
num_dict.append('sextillion')
num_dict.append('septillion')
num_dict.append('octillion')
num_dict.append('nonillion')
for prefix_hundreds in d:
#tillion can't be used first time round
if not prefix_hundreds:
b = c[1:]
else:
b = c
for prefix_tens in b:
for prefix in a:
num_dict.append(prefix_hundreds+prefix+prefix_tens)