Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Your goal is to print (to the standard output) the largest number possible, using just ten characters of code.

  • You may use any features of your language, except built-in exponentiation functions.
    • Similarly, you may not use scientific notation to enter a number. (Thus, no 9e+99.)
  • The program must print the number without any input from the user. Similarly, no reading from other files, or from the Web, and so on.
  • Your program must calculate a single number and print it. You can not print a string, nor can you print the same digit thousands of times.
  • You may exclude from the 10-character limit any code necessary to print anything. For example, in Python 2 which uses the print x syntax, you can use up to 16 characters for your program.
  • The program must actually succeed in the output. If it takes longer than an hour to run on the fastest computer in the world, it's invalid.
  • The output may be in any format (so you can print 999, 5e+100, etc.)
  • Infinity is an abstract concept, not a number. So it's not a valid output.
share|improve this question
2  
8  
What do you exactly mean by "calculate". Also, If it takes longer than an hour to run on any computer in the world, it's invalid. is not objective. I could (theoretically) manufacture a computer that takes an hour to change one T-state –  user80551 yesterday
3  
Does bit-shift count as an exponentiation operator since it is equivalent to * 2^x ? –  Claudiu yesterday
4  
The fact that the time limit depends on the performance of the fastest computer in the world makes it impossible for us to determine the set of valid answers... I don't really like that –  David Z yesterday
3  
@DavidZ: True. I'd like to see it changed to "1 hour on X computer", and also clarify the rules as to bit-shift, and whether other large built-in functions (e.g. ack in Wolfram) are allowed. I guess not the best question, but I enjoyed playing to the spirit of the rules –  Claudiu yesterday
show 10 more comments

38 Answers

Perl, >1.96835797883262e+18

time*time

Might not be the largest answer... today! But wait enough millennia and it will be!


Edit:

To address some of the comments, by "enough millenia," I do in fact mean n100s of years.

To be fair, if the big freeze/heat death of the universe is how the universe will end (estimated to occur ~10100 years), the "final" value would be ~10214, which is certainly much less than some of the other responses (though, "random quantum fluctuations or quantum tunneling can produce another Big Bang in 101056 years"). If we take a more optimistic approach (e.g. a cyclic or multiverse model), then time will go on infinitely, and so some day in some universe, on some high-bit architecture, the answer would exceed some of the others.

On the other hand, as pointed out, time is indeed limited by the size of integer/long, so in reality something like ~0 would always produce a larger number than time (i.e. the max time supported by the architecture).

This wasn't the most serious answer, but I hope you guys enjoyed it!

share|improve this answer
6  
Upvoted because I like the eventuality –  Tim Gostony yesterday
2  
Won't time wrap around and return a small number at some point? Depends on whether it's 32-bit or 64-bit perl I guess –  Claudiu yesterday
    
@AllenG: Where does perl get the data source for time from? If it's from the system which uses unsigned ints, then it will wrap around. –  Claudiu yesterday
    
Right, I misinterpreted the comment. Well, hopefully by the time the universe is ready, computers/Perl will have increased the size of their integers :). –  Allen G yesterday
2  
1000 years ~ 3e10 seconds, so you'll still be hovering around 1e21 as your output. Perhaps if you waited 1e50 years, you might start competing against the other answers? –  Kyle Kanos yesterday
show 3 more comments

CJam, 2 × 10268,435,457

A28{_*}*K*

This computes b, defined as follows:

  • a0 = 10

  • an = an - 12

  • b = 20 × a28

$ time cjam <(echo 'A28{_*}*K*') | wc -c
Real    2573.28
User    2638.07
Sys     9.46
268435458

Background

This follows the same idea as Claudiu's answer, but it isn't based on it. I had a similar idea which I posted just a few minutes after he posted his, but I discarded it since it didn't come anywhere near the time limit.

However, aditsu's suggestion to upgrade to Java 8 and my idea of using powers of 10 allowed CJam to calculate numbers beyond the reach of GolfScript, which seems to be due to some bugs/limitations of Ruby's Bignum.

How it works

A    " Push 10.                                                          ";
28{  " Do the following 28 times:                                        ";
  _* " Duplicate the integer on the stack and multiply it with its copy. ";
}*   "                                                                   ";
K*   " Multiply the result by 20.                                        ";

CJam, ≈ 8.1 × 101,826,751

KK,{)*_*}/

Takes less than five minutes on my machine, so there's still room for improvement.

This computes a20, defined as follows:

  • a0 = 20

  • an = (n × an - 1)2

How it works

KK,   " Push 20 [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ]. ";
{     " For each integer in the array:                                 ";
  )*  " Increment it and compute the its product with the accumulator. ";
  _*  " Multiply the result with itself.                               ";
}/
share|improve this answer
9  
Haha, is that Kirby? :) –  aditsu yesterday
    
Could you describe what this is doing? –  Kyle Kanos yesterday
    
Thanks! That's pretty cool. –  Kyle Kanos yesterday
    
FYI, I ran some tests to check BigInteger performance - I calculated 100000! and converted to string. Results: java 6: 21 sec calculation, 44 sec toString; java 7: 14 sec calculation, 42 sec toString; java 8: 5 sec calculation, 1 sec toString! –  aditsu yesterday
    
@aditsu: Upgrading Java reduced the runtime from 5 minutes to 2 seconds! –  Dennis yesterday
add comment

K/Kona: 8.977649e261 1.774896e308

*/1.6+!170
  • !170 creates a vector of numbers from 0 to 169
  • 1.6+ adds one to each element of the vector & converts to reals (range is 1.6 to 170.6)
  • */ multiplies each element of the array together

If Kona supported quad precision, I could do */9.+!999 and get around 1e2584. Sadly, it doesn't and I'm capped to double precision.


old method

*/9.*9+!99
  • !99 creates a vector of numbers from 0 to 98
  • 9+ adds 9 to each element of the vector (now ranges 9 to 107)
  • 9.* multiplies each element by 9.0 (implicitly converting to reals, so 81.0 through 963.0)
  • */ multiplies each element of the vector together
share|improve this answer
add comment

Python shell, 3,010,301 digits

9<<9999999

Calculating the length: Python will append a "L" to these long numbers, so it reports 1 character more than the result has digits.

>>> len(repr( 9<<9999999 ))
3010302

First and last 20 digits:

40724177878623601356... ...96980669011241992192
share|improve this answer
1  
Darn it! This showed up whilst I was writing the same answer –  James_pic yesterday
1  
That's really just 9 * 2**9999999, so one could argue it uses exponentiation. –  Dennis yesterday
1  
Wait, ***built-in*** exponentiation functions are not allowed so this might slip under the rules. +1 –  user80551 yesterday
    
Mathematical way of computing the length: floor(log10(9 * 2**9999999))+1 –  Quincunx yesterday
    
@Quincunx: Yes... because showing the length is no proof for really having calculated the number I added 40 digits of it. If needed I can add a shasum or something similar too... –  yeti yesterday
show 3 more comments

Wolfram ≅ 2.003529930 × 1019728

Yes, it's a language! It drives the back-end of the popular Wolfram Alpha site. It's the only language I found where the Ackermann function is built-in and abbreviated to less than 6 characters.

In eight characters:

$ ack(4,2)

200352993...719156733

Or ≅ 2.003529930 × 1019728

ack(4,3), ack(5,2) etc. are much larger, but too large. ack(4,2) is probably the largest Ackermann number than can be completely calculated in under an hour.

Larger numbers are rendered in symbolic form, e.g.:

$ ack(4,3)

2↑²6 - 3 // using Knuth's up-arrow notation

The rules say any output format is allowed, so this might be valid. This is greater than 101019727, which is larger than any of the other entries here except for the repeated factorial.

However,

$ ack(9,9)

2↑⁷12 - 3

is larger than the repeated factorial. The largest number I can get in ten characters is:

$ ack(99,99)

2↑⁹⁷102 - 3

This is insanely huge, the Universe isn't big enough to represent a significant portion of its digits, even if you took repeated logs of the number.

As large as it is, Graham's number surpasses anything expressible as an Ackermann number.

share|improve this answer
    
Why does the exponent look weird? Is it 10 ^ 19278 or something else? –  Claudiu yesterday
6  
Not bad, but it's no match for my ack(4,2)+1 solution. –  user19057 yesterday
1  
ack(4,2)+2, I WIN –  edvinas.me yesterday
    
Is the source available for the Wolfram language? –  Kyle Kanos yesterday
    
@Claudiu - Superscripts 1-3 are in a different UNICODE block from 0,4-9. Automatic font substitution tries to match the fonts but can't always. –  Yimin Rong 16 hours ago
show 1 more comment

J (((((((((9)!)!)!)!)!)!)!)!)

Yeah, that's a lot. 10^(10^(10^(10^(10^(10^(10^(10^6.269498812196425))))))) to be not very exact.

!!!!!!!!9x
share|improve this answer
2  
Does it actually output the number? Is there a free J compiler out there? –  Kyle Kanos yesterday
1  
I did find a compiler, but after 20 minutes, !!9x hasn't printed anything to screen. I sincerely doubt that !!!!!!!!9x will ever be computed. –  Kyle Kanos yesterday
9  
"If it takes longer than an hour to run on the fastest computer in the world, it's invalid." Not sure this would be valid since it doesn't run within an hour –  Claudiu yesterday
4  
It took 70 minutes, but !!9x finally printed to screen. I'm impressed that it actually computed the value, but it still completely fails bullet 5. –  Kyle Kanos yesterday
4  
@Quincunx: Likely true, however the condition for a valid answer is that the program must succeed in output; this answer completely fails that criterion. Sadly, the upvoters have neglected all the comments pointing this out and still upvote it over the CJam & Golfscript answers that are insanely huge and compute in reasonable time. –  Kyle Kanos yesterday
show 19 more comments

Any language with short enough constant names, 18 digits approx.

99/sin(PI)

I would post this as a PHP answer but sadly M_PI makes this just a little too long! But PHP yields 8.0839634798317E+17 for this. Basically, it abuses the lack of absolute precision in PI :p

share|improve this answer
    
Can't you do tan(PI/2)? –  user80551 yesterday
    
@user80551 Could do, but I just noticed that I could make use of that last remaining character in the limit to boost my result by 99 times. –  Niet the Dark Absol yesterday
    
Too long in Common Lisp: (/ 99(sin pi)) (14 characters). Error in TI-83: 99/sin(π (8 characters) causes division by zero. Works in LibreOffice Calc: =99/SIN(PI( (10 characters, not counting =) computes 808423047055000000. LibreOffice auto-inserts the last two )) in =99/SIN(PI()). –  kernigh yesterday
    
It's depending on the precision of the language. In PHP 14 decimal digits is a common value. –  kenorb 18 hours ago
    
@kernigh It doesn't matter in this case, but would 99/sin(π be five bytes or eight? I know TI-BASIC stores a bunch of commands as single bytes; is sin( one of them? –  WChargin 3 hours ago
add comment

Python - Varies, up to 13916486568675240 (so far)

Not entirely serious but I thought it would be kinda fun.

print id(len)*99

Out of all the things I tried, len was most consistently getting me large ids.

Yielded 13916486568675240 (17 digits) on my computer and 13842722750490216 (also 17 digits) on this site. I suppose it's possible for this to give you as low as 0, but it could also go higher.

share|improve this answer
    
Great idea but unfortunately it doesn't calculate anything. –  user80551 yesterday
1  
I do believe the *99 part invokes a calculation. –  commando yesterday
    
Oh yes, /me feels stupid now. –  user80551 yesterday
    
If you use something shorter - say id(id) or id(0j), you can multiply by 999 –  gnibbler yesterday
1  
Out of smaller named ones in docs.python.org/2/library/functions.html , vars consistently gives the highest value(but 4 chars) followed by sum. Use print(sorted([(id(x),x)for x in[id,len,max,min,str,int,ord,chr,sum,map,abs,all,any,bin,bool,eval,oct,vars,ite‌​r,list,set,repr,round,zip,type,pow,dict,dir,hex]])[::-1]) to check. –  user80551 yesterday
show 1 more comment

Golfscript, 1e+33,554,432

10{.*}25*

Computes 10 ^ (2 ^ 25), without using exponents, runs in 96 seconds:

$ time echo "10{.*}25*" | ruby golfscript.rb  > BIG10

real    1m36.733s
user    1m28.101s
sys     0m6.632s
$ wc -c BIG10
 33554434 BIG10
$ head -c 80 BIG10
10000000000000000000000000000000000000000000000000000000000000000000000000000000
$ tail -c 80 BIG10
0000000000000000000000000000000000000000000000000000000000000000000000000000000

It can compute up to 9 ^ (2 ^ 9999), if only given enough time, but incrementing the inner exponent by one makes it take ~triple the time, so the one hour limit will be reached pretty soon.

Explanation:

Using a previous version with the same idea:

8{.*}25*

Breaking it down:

8         # push 8 to the stack
{...}25*  # run the given block 25 times

The stack at the start of each block consists of one number, the current number. This starts off as 8. Then:

.         # duplicate the top of the stack, stack is now | 8 | 8 |
*         # multiply top two numbers, stack is now       | 64 |

So the stack, step by step, looks like this:

8
8 8
64
64 64
4096
4096 4096
16777216
16777216 16777216

... etc. Written in math notation the progression is:

n=0, 8                     = 8^1  = 8^(2^0)
n=1, 8*8                   = 8^2  = 8^(2^1)
n=2, (8^2)*(8^2) = (8^2)^2 = 8^4  = 8^(2^2)
n=3,               (8^4)^2 = 8^8  = 8^(2^3)
n=4,               (8^8)^2 = 8^16 = 8^(2^4)
share|improve this answer
    
What's the deal with the two one's in front of the 2564 in your output? –  Kyle Kanos yesterday
    
@KyleKanos: That's not my output, it's the output of wc. I'll edit to make it clearer –  Claudiu yesterday
    
you could use wc -c to make the output clearer –  daniero yesterday
    
Nice! I had the same idea a few minutes ago, but it runs much slower with CJam (which is surprising, since it's faster than GolfScript in general). –  Dennis yesterday
1  
Minor improvement: 10{.*}25 delivers 33,554,434 digits and finishes in 90 second on my machine. I don't know why, but 10{.*}26* prints nothing. –  Dennis yesterday
show 10 more comments

Python 3, 9*2^(2^35) > 10^10,343,311,894

My number is:

9<<(1<<35)

Ten characters exactly.

I am printing the number in hex, and

You may exclude from the 10-character limit any code necessary to print anything. For example, in Python 2 which uses the print x syntax, you can use up to 16 characters for your program.

Therefore, my actual code is:

print(hex(9<<(1<<35)))

Proof that it runs in the specified time and generates a number of the specified size:

$ time python bignum.py > bignumoutput.py 

real    2m27.213s
user    0m38.001s
sys    0m13.572s
$ wc -c bignumoutput.py 
8589934597 bignumoutput.py

Greater than 10^(8589934594*log(16))=10^10,343,311,894

Python 3 is necessary because in python 2, 1<<35 would be a long, and << doesn't take longs as inputs.

I can't use 9*2^(2^36)) instead because:

Traceback (most recent call last):
  File "bignum.py", line 1, in <module>
    print(hex(9<<(1<<36)))
MemoryError

In all likelihood, the fastest machine in the world has more memory than I do, so my alternate answer is:

9<<(9<<99)

9*2^(9*2^99) > 10^(1.7172038461*10^30)

However, my current answer is the largest anyone has submitted, so it's probably good enough. Also, this is all assuming bit-shifting is allowable. It appears to be, from the other answers using it.

share|improve this answer
    
So far this looks to be the largest answer by far. It's a 10,000,000,000 digit number, after all. –  nneonneo 13 hours ago
add comment

Powershell - 1.25371912013172E+35

99PB*999PB

Multiplies 99 Petabytes times 999 Petabytes.

share|improve this answer
1  
98901 sq petabytes? Is that some sort of method to measure the surface bit density of (future high-capacity)hard-disks? –  user80551 14 hours ago
add comment

Haskell, 4950

Aww man, that's not a lot! 10 characters start after the dollar sign.

main=putStr.show$sum[1..99]
share|improve this answer
    
Why not just print? Also, 9/0.000001 is greater than sum[1..99]. –  Taylor Fausak yesterday
3  
At that rate, we might consider 9 999 999 999 to be a lower bound on results. –  Cory yesterday
add comment

Haskell

Without any tricks:

main = print -- Necessary to print anything
    $9999*9999 -- 999890001

Arguably without calculating anything:

main = print
    $floor$1/0 -- 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216

Adapting Niet's answer:

main = print
    $99/sin pi -- 8.083963479831708e17
share|improve this answer
    
Third bullet says "Your program must calculate..." –  user80551 yesterday
    
floor(infinity) is a finite number? What the heck Haskell? –  nneonneo 13 hours ago
add comment

Python shell, 649539 999890001

Beats Haskell, not really a serious answer.

99999*9999
share|improve this answer
3  
9999999999 is larger, isn't it? –  MadTux yesterday
3  
@MadTux There is an ambiguous restriction to calculate the answer. –  user80551 yesterday
1  
If this answer is correct, then mine 9**9**9**9 is correct either, as it's arithmetic operator (not built-in func). –  kenorb 14 hours ago
1  
@kenorb It's built in exponentiation that's not allowed. –  user80551 14 hours ago
add comment

wxMaxima ~3x1049,948 (or 108,565,705,514 )

999*13511!

Output is

269146071053904674084357808139[49888 digits]000000000000000000000000000000

Not sure if it quite fits specs (particularly the output format one), but I can hit even larger:

bfloat(99999999!)

Output is

9.9046265792229937372808210723818b8565705513

That's roughly 108,565,705,514 which is significantly larger than most of the top answers and was computed in about 2 seconds. The bfloat function gives arbitrary precision.

share|improve this answer
add comment

JavaScript, 12624366232773, conditional on the legality of clock-reading

9*new Date

I don't think we should be allowed to refer to the clock for this, since it's essentially taking an input. However, the technique seems to be well-received here.

If clocks are not allowed, then:

JavaScript, 186025771008

99*(7<<28)

With printing:

console.log(99*(7<<28))

Can't use any trigonometry without feeding bytes to something like Math.sin, and Math.PI.

Odd that this code might work in many different languages. This answer is particular to JS because it uses bit-shift to go near the integer maximum, then multiplies to get a floating point.

share|improve this answer
    
Bit shift operation are limited to 32 bit integers. 60 == 28 used in a shift operation (try in console: [7<<28, 7<<60]) –  edc65 yesterday
    
Fine, fine. 60's a bit prettier than 28, but I guess it's not worth any misunderstandings. –  Cory yesterday
add comment

Mathematica, 2.174188391646043*10^20686623745

$MaxNumber

Ten characters exactly.

share|improve this answer
5  
Is it technically calculating anything, and is it outputting all the digits and not just scientific notation? –  Yimin Rong yesterday
    
@Yimin: The output may be in any format (so you can print 999, 5e+100, etc.) –  edc65 yesterday
    
The value is not set at compile-time, but depends on the particular machine on which the command is run. I think it counts. –  Michael Stern yesterday
add comment

CJam - 40.4 million digits

1X27m<m<

Assuming bit shift is ok, this calculates 1<<(1<<27). It takes about 15 minutes on my laptop, using java 8 to run the interpreter.

share|improve this answer
    
Hey, aditsu, did you design CJam? –  404 Not Found 19 hours ago
2  
@404NotFound yeah, but a lot of it is like GolfScript –  aditsu 14 hours ago
1  
Cool, where did you learn parsing to write an interpreter? I'm really interested in parsing etc., but I'm only 12 (no CS courses ;() I'm currently reading "Parsing Techniques: a Practical Guide" and trying to write my toy compiler in C++ –  404 Not Found 10 hours ago
add comment

TXR:

$ txr -p '(mask 999)'
535754303593133660474212524530000905280702405852766803721875194185175525562468061246
599189407847929063797336458776573412593572642846157810728751889829846429852761096554
990320661140395677219337642394922319490470301292036210344653556258987007434741839952
7286296858625998634149561158533358569939198279680
share|improve this answer
add comment

Bash / shell

You may exclude from the 10-character limit any code necessary to print anything.

... you can use up to 16 characters for your program.

(6 chars for code + 7 chars for printing = 26 digits) = 6888888 digits

$ seq -s9 999999

This number is bigger, but people may argue that it's in the wrong format.

The output may be in any format (so you can print 999, 5e+100, etc.).

(8 chars for code + 8 chars for printing = 26 digits) = more than 1183888008 digits

$ seq -s9 99999999

It usually takes around a minute to print the number and it contains the scientific representation of it.


Some funny example:

(10 chars = 26 digits)

echo $$$$$$$$$$
2760127601276012760127601

See: What does $$ mean in the shell?

share|improve this answer
    
Your program must calculate a single number and print it. You can not print a string, nor can you print the same digit thousands of times. –  aditsu 13 hours ago
add comment

Python 2.7 - 8794643931199480236 15616093818140822

print hash('zz')
share|improve this answer
6  
Um, that's 12 chars. –  user80551 yesterday
    
Ehh valid point @user80551. Guess I was slightly distracted by the footy match on TV :-) –  willem 22 hours ago
add comment

Scala, 263-1

Poor, poor Scala. Takes at least 8 characters to get a BigInt value, which doesn't leave enough room to actually make it big.

But with only 7 characters of (counted) code, we can print the largest possible positive Long:

print(-1L>>>1)
share|improve this answer
add comment

Befunge-93 (1,853,020,188,851,841)

Glad nobody has done Befunge yet (it's my niche), but dammit I can't find any clever trick to increase the number.

9:*:*:*:*.

So it's 9^16.

:*

Basically multiplies the value at the top of the stack with itself. So, value at the top of the stack goes:

9
81
6561
43046721
1853020188851841

and

.

Outputs the final value. I would be interested to see if anybody has any better ideas.

share|improve this answer
add comment

Perl, 1.84467422290351e+26 (On a 64-bit machine)

perl -le "print ~0*9999999"
share|improve this answer
add comment

I'd rather post this as a comment above, but apparently I can't since I'm a noob.

Python:

9<<(2<<29)

I'd go with a larger bit shift, but Python seems to want the right operand of a shift to be a non-long integer. I think this gets closer to the theoretical max:

9<<(7<<27)

The only problem with these is that they might not satisfy rule 5.

share|improve this answer
add comment

C++ prints 18446744073709551615

#

ULLONG_MAX is 10 characters.

#include <iostream>
#include <limits.h>
using namespace std;
int main()
{
cout<<ULLONG_MAX<<endl;
return 0;
}
share|improve this answer
1  
And what value does that print? –  Kyle Kanos yesterday
    
@KyleKanos Fixed it, thanks –  bacchusbeale 23 hours ago
add comment

Perl: 6.27710173538668e+57 on cygwin with a Perl 32 bit

perl -e 'print ~0*~0*~0, "\n"'
share|improve this answer
add comment

units interactive shell, 3.085369e+68

You read that right, I know it's not much but it's definitely different.

9999Ypc
ym

I'm assuming newline counts as a character and the invocation of units counts as code essential to print. Ypc is yotta parsec, ym is yocto meter.

You have: 9999Ypc
You want: ym
    * 3.085369e+68
    / 3.2411034e-69
share|improve this answer
add comment

Perl

9x99999999

Try it like that:

D:>perl -e "print 9x99999999" > bigNum.txt

D:>dir bigNum.txt
 Volume in drive C has no label.
 Volume Serial Number is F02E-11C0

 Directory of d:\

14.06.2014 г.  18:52        99 999 999 bigNum.txt
               1 File(s)     99 999 999 bytes
               0 Dir(s)  34 293 600 256 bytes free

Or if you're patient you can just execute perl -e "print 9x99999999" and enjoy almost 100MB of 9's printed to your console :)

share|improve this answer
add comment

Matlab (1.7977e+308)

Matlab stores the value of the largest (double-precision) floating-point number in a variable called realmax. Invoking it in the command window (or at the command line) prints its value:

>> realmax

ans =

  1.7977e+308
share|improve this answer
add comment

protected by Dennis 9 hours ago

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.