Your task is to create many programs. The first outputs 1, the second outputs 2, etc. The higher you can go, the better!

However, all of these programs must be made the same list of characters. You can choose which characters to put in the list. Each program can only use a character as many times as it appears in the list.

For example, using the Python shell:

List of characters:  +122
Program 1:      1
Program 2:      2
Program 3:      1+2
Program 4:      2+2   (2 appears twice in the list)

It is impossible to make a program which prints 5 without reusing the + character, so there are a total of 4 programs possible with this list. (Only consecutive numbers starting from 1 count. We therefore ignore other numbers we can make, like 12.)


  • Let N be the number of programs.
  • Let S be the size of the shortest program, or 15, whichever is less.
  • Let L be the length of the list.

Your score is N / Γ((L-S)/5), where Γ is the gamma function.

In the example above, N is 4; S is 1; L is 4; the score is 4 / Γ((4-1)/5) = 2.686.

Highest score wins!

Below is a Stack Snippet to help calculate your score:

var g=7,C=[0.99999999999980993,676.5203681218851,-1259.1392167224028,771.32342877765313,-176.61502916214059,12.507343278686905,-0.13857109526572012,9.9843695780195716e-6,1.5056327351493116e-7];function gamma(z) {if(z<0.5){return Math.PI/(Math.sin(Math.PI*z)*gamma(1-z));}else{z--;var x=C[0];for(var i=1;i<g+2;i++)x+=C[i]/(z+i);var t=z+g+0.5;return Math.sqrt(2*Math.PI)*Math.pow(t,(z+0.5))*Math.exp(-t)*x;}}function go(){var N=parseInt(jQuery('#programs').val()),S=parseInt(jQuery('#shortest').val()),L=parseInt(jQuery('#length').val());if(S>15){S=15;}jQuery('#score').val(N/gamma((L-S)/5));}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><form><table><tr><td><label>Number of programs:</label></td><td><input id='programs' oninput="go()" value='0'/></td></tr><tr><td><label>Size of shortest program:</label></td><td><input id='shortest' oninput="go()" value='0'/></td></tr><tr><td><label>Size of list:</label></td><td><input id='length' oninput="go()" value='0'/></td></tr><tr><td><label>Score:</label></td><td><output id='score'>0</output></td></tr></table></form><p>Code from <a href="http://stackoverflow.com/a/15454784/3148067">http://stackoverflow.com/a/15454784/3148067</a></p>


  • You can use programs or functions.
  • You may use different languages for different numbers.
  • Each program must work by itself. For example, you can not assume that the first program will run before the second program.
  • 1
    \$\begingroup\$ So... if I have a single program of size 1, then I get a better score if my list is 8 long (score 1.127) as opposed to 1 (score 0)? \$\endgroup\$ – Sp3000 May 4 '15 at 18:07
  • \$\begingroup\$ @Sp3000 Correct. \$\endgroup\$ – Ypnypn May 4 '15 at 18:12
  • \$\begingroup\$ So we should arbitrarily pad programs and/or lists to get a better score? Just checking. \$\endgroup\$ – Geobits May 4 '15 at 18:13
  • \$\begingroup\$ @Geobits The bonus for a long shortest program is to give languages other than CJam/Pyth to compete. And yes, if it helps your score. \$\endgroup\$ – Ypnypn May 4 '15 at 18:15
  • \$\begingroup\$ What is that gamma function? checking wiki, it seems to be (n-1)! ? but that doesn't spit out 2.686 like your sample does? Also - do CR/LFs count for length ? \$\endgroup\$ – Ditto May 4 '15 at 18:47

Pyth, Score of 1.664 * 10^26

Since you only have L different chars to choose from, you can maximal generate O(L!) different programs.

So lets build something really close: By indexing permutations of the alphabet:

I use a following list of characters is:


With these characters I can generate 26!-1 different programs like this:

Program 1: x.pG"abcdefghijklmnopqrstuvwxzy
Program 2: x.pG"abcdefghijklmnopqrstuvwyxz
Program 3: x.pG"abcdefghijklmnopqrstuvwyzx
Program 403291461126605635583999999: x.pG"zyxwvutsrqponmlkjihgfedcba

Notice I didn't use "abcdefghijklmnopqrstuvwxyz" (sorted alphabet), since I give an index of 0.

So we got N = 403291461126605635583999999, S = 15, L = 31, which gives a score of 1.663767345141228e+26.


   G       G is pre-initialized with "abc...xyz"
 .p        gives all possible permutations
x   "...   the index of "..." in the permutation list

Notice, that none of the programs will actually run. Because of memory and time.


You can even get way higher. For instance by using also the uppercase letters. Gives me a score of about 10^76.

edit 2: a runnable version

Since none of the programs above is actually runnable, here's one that works.


The programs are:

Program 1: x.pSK"abced"K
Program 2: x.pSK"abdce"K
Program 3: x.pSK"abdec"K
Program 117: x.pSK"edbca"K
Program 118: x.pSK"edcab"K
Program 119: x.pSK"edcba"K

Here's an online Demonstration.


    K"abced"   K = "abced"
   S           sort it
 .p            generate all permutations of sorted(K)
x           K  index of K in the permutations. 

N = 119, S = 13, L = 13 gives a score of 0. But If we simply use a dummy char to the list we get N = 119, S = 13, L = 14 and a score of 25.92

Of course we can use more chars than abcde for the permutation. If we use n different chars, we get N = n!-1, S = 15, L = n+8, which gives a score of ~n!/(n-7)!. So we can get pretty much an unlimited score.

  • \$\begingroup\$ We have a winner. Unless someone can get to a googol. \$\endgroup\$ – ASCIIThenANSI May 4 '15 at 19:46
  • \$\begingroup\$ I recognize that you are allowed to create as a function, but this also seems to violate Each program must work by itself., as it requires another something to set up the array outside the function, and as such it's not entirely self contained. @Ypnypn, what is your take here? \$\endgroup\$ – tfitzger May 4 '15 at 21:32
  • 1
    \$\begingroup\$ @tfitzger Are you referring to the G variable? Because that's pre-initialized by the language, not by the user. \$\endgroup\$ – Runer112 May 5 '15 at 1:55
  • \$\begingroup\$ @Runer112 Edit 2 explicitly states that none of the prior code is runnable and then gives an example where an array appears to be populated before being run. The wording of this post, for someone who doesn't know Pyth, makes it appear that they have to initialize the G variable, since it never explicitly states that G is a system variable. Thank you for the clarification. \$\endgroup\$ – tfitzger May 5 '15 at 13:55
  • \$\begingroup\$ Or if someone can get to a giggolplex, or a dossol, or n![999999999] using HAN, where n=99999!. \$\endgroup\$ – user75200 Jan 13 '18 at 17:55


Character list (length 8): 12347+*^

I have constructed programs through 95 for this one. I have yet to discover one given this character set for 96.

So that gives a score of- according to the calculator snippet provided by the OP- about 107.1 so far.

Some of my constructed programs:

1 = 1
2 = 2
3 = 3
4 = 4
5 = 2+3
6 = 2*3
7 = 7
8 = 2^3
9 = 3^2
10 = 7+3
20 = 14+2*3
30 = 2+4*7
40 = 12+4*7
50 = 7^2+1
60 = 43+17
70 = 7^2+21
80 = 7^2+31
90 = 4^3+2*13
95 = 74+21

CJam, 101023.64023653832850 > 10 400 000 000 000 000 000 000 000


Each program consists of 9 + 63 486 × 1020 characters:

  • ""_e!\a#)
  • 1020 copies of all Unicode characters in the range 065 535, except "\ and surrogates.


The structure of each program is:


where denotes a permutation of all 63 486 aforementioned Unicode characters.

_e! computes all possible permutations of the characters in sorted order.

\a# computes the index of the original permutation in the list of all of them. ) adds 1 to that index to generate only positive integers.


If the 1020 copies of each of the 63 486 characters were somehow different, there would be a total of (63 486 × 1020)! different ways to arrange them.

However, for each of the 63 486 characters, this generates 1020! identical permutations, since this is the number of ways the copy of this single character can be arranged.

Therefore, the number of different permutations is (63 486 × 1020)! / (1020!)63 486.

Plugging this number and the character count into WolframAlpha reveals the score from the top.


Of course, enumerating all possible permutations isn't very efficient and even storing 6 × 1024 characters isn't possible on my computer.

Using the online interpreter and more efficient code, I can permute one copy of 1 000 characters in a few seconds for a score of 3 × 102 189.

The highest number it produces is generated by the following code:


Copying and pasting the code from above should work just fine.

Using the Java interpreter, I can use one copy of all 63 486 characters and execute the code in under five and a half hours:

$ cjam <(echo '65536,2048,55296f+-:c"\"\\"-W%`"_${\(_3$#2$,m!*X+:X;@^}hX"') > test.cjam
$ time test.cjam > /dev/null

real    324m36.040s
user    331m55.488s
sys     0m54.971s

This method achieves a score of 7.6 × 10230 732.


(redone as previous was loophole - sorry about that). (edited to fix score: N=8, due to gaps - forgot about that)

Unix/Korn Shell (Score: 9.016) (going a very simple method, just trying to maximize the Gamma function)

List is: (L=13)

 echo 12345678

8 Programs:

  echo 1
  echo 2
  echo 8



Hopefully no loopholes this time around - I just crunched the formula and figured out where to maximize it. For my method, it maximized at S=6 and L=13. :)

Wolfram Alpha tells me:

8 / Γ((13-6)/5) = 9.016
  • 2
    \$\begingroup\$ This is a standard loophole: meta.codegolf.stackexchange.com/a/1789/16294 \$\endgroup\$ – Ypnypn May 4 '15 at 19:04
  • \$\begingroup\$ Ok .. reworked it .. hopefully no loop holes this time ? \$\endgroup\$ – Ditto May 4 '15 at 19:44
  • \$\begingroup\$ You have to print all numbers from 1 to N. With your list, you can't print 11. \$\endgroup\$ – Martin Ender May 4 '15 at 19:47
  • \$\begingroup\$ Yeah, just noticed that as well :) lol ... tricky .. (oh well, going to leave this her and let it sink ... sigh ... ) :) \$\endgroup\$ – Ditto May 4 '15 at 19:47
  • 2
    \$\begingroup\$ It's considered good manners around here to delete invalid answers, and undelete them once they are fixed. That will also help you avoid unnecessary downvotes. \$\endgroup\$ – Martin Ender May 4 '15 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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