# Many programs, few characters

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.)

## Scoring

• 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>

## Rules

• 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.
• 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)? Commented May 4, 2015 at 18:07
• @Sp3000 Correct. Commented May 4, 2015 at 18:12
• So we should arbitrarily pad programs and/or lists to get a better score? Just checking. Commented May 4, 2015 at 18:13
• @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. Commented May 4, 2015 at 18:15
• 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 ? Commented May 4, 2015 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:

abcdefghijklmnoppqrstuvwxxyzG."


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.

### Explanation:

x.pG"...
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.

# edit:

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.

x.pSK""Kabcde


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.

### Explanation:

x.pSK"abced"K
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.

• We have a winner. Unless someone can get to a googol. Commented May 4, 2015 at 19:46
• 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? Commented May 4, 2015 at 21:32
• @tfitzger Are you referring to the G variable? Because that's pre-initialized by the language, not by the user. Commented May 5, 2015 at 1:55
• @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. Commented May 5, 2015 at 13:55
• Or if someone can get to a giggolplex, or a dossol, or n![999999999] using HAN, where n=99999!. Commented Jan 13, 2018 at 17:55

# TI-84 BASIC, score 107.07

Character list (length 8): 12347+*^

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
11 = 7+4
12 = 12
13 = 13
14 = 14
15 = 2*7+1
16 = 2^4
17 = 17
18 = 2*7+4
19 = 2^4+3
20 = 14+2*3
21 = 3*7
22 = 3*7+1
23 = 23
24 = 24
25 = 24+1
26 = 2*13
27 = 27
28 = 4*7
29 = 1+4*7
30 = 2+4*7
31 = 31
32 = 32
33 = 32+1
34 = 34
35 = 34+1
36 = 34+2
37 = 37
38 = 37+1
39 = 37+2
40 = 12+4*7
41 = 41
42 = 42
43 = 43
44 = 43+1
45 = 43+2
46 = 32+14
47 = 47
48 = 47+1
49 = 7^2
50 = 7^2+1
51 = 3*17
52 = 4*13
53 = 3*17+2
54 = 4*13+2
55 = 3*17+4
56 = 7*2^3
57 = 7*2^3+1
58 = 37+21
59 = 42+17
60 = 43+17
61 = 37+24
62 = 31*2
63 = 7*3^2
64 = 4^3
65 = 4^3+1
66 = 4^3+2
67 = 7*3^2+4
68 = 4*17
69 = 27+14*3
70 = 43+27
71 = 71
72 = 72
73 = 73
74 = 74
75 = 74+1
76 = 74+2
77 = 74+3
78 = 2*37+4
79 = 47+32
80 = 7^2+31
81 = 3^4
82 = 3^4+1
83 = 3^4+2
84 = 7*12
85 = 4^3+21
86 = 2*43
87 = 7*12+3
88 = 7*12+4
89 = 73+2^4
90 =  7^2+41
91 = 7*13
92 = 7^2+43
93 = 7*13+2
94 = 2*47
95 = 7*13+4


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

### Characters

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.

### Programs

The structure of each program is:

"…"_e!\a#)


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.

### Scoring

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.

### Bonus

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:

"㢣㢢㢡㢠㢟㢞㢝㢜㢛㢚㢙㢘㢗㢖㢕㢔㢓㢒㢑㢐㢏㢎㢍㢌㢋㢊㢉㢈㢇㢆㢅㢄㢃㢂㢁㢀㡿㡾㡽㡼㡻㡺㡹㡸㡷㡶㡵㡴㡳㡲㡱㡰㡯㡮㡭㡬㡫㡪㡩㡨㡧㡦㡥㡤㡣㡢㡡㡠㡟㡞㡝㡜㡛㡚㡙㡘㡗㡖㡕㡔㡓㡒㡑㡐㡏㡎㡍㡌㡋㡊㡉㡈㡇㡆㡅㡄㡃㡂㡁㡀㠿㠾㠽㠼㠻㠺㠹㠸㠷㠶㠵㠴㠳㠲㠱㠰㠯㠮㠭㠬㠫㠪㠩㠨㠧㠦㠥㠤㠣㠢㠡㠠㠟㠞㠝㠜㠛㠚㠙㠘㠗㠖㠕㠔㠓㠒㠑㠐㠏㠎㠍㠌㠋㠊㠉㠈㠇㠆㠅㠄㠃㠂㠁㠀㟿㟾㟽㟼㟻㟺㟹㟸㟷㟶㟵㟴㟳㟲㟱㟰㟯㟮㟭㟬㟫㟪㟩㟨㟧㟦㟥㟤㟣㟢㟡㟠㟟㟞㟝㟜㟛㟚㟙㟘㟗㟖㟕㟔㟓㟒㟑㟐㟏㟎㟍㟌㟋㟊㟉㟈㟇㟆㟅㟄㟃㟂㟁㟀㞿㞾㞽㞼㞻㞺㞹㞸㞷㞶㞵㞴㞳㞲㞱㞰㞯㞮㞭㞬㞫㞪㞩㞨㞧㞦㞥㞤㞣㞢㞡㞠㞟㞞㞝㞜㞛㞚㞙㞘㞗㞖㞕㞔㞓㞒㞑㞐㞏㞎㞍㞌㞋㞊㞉㞈㞇㞆㞅㞄㞃㞂㞁㞀㝿㝾㝽㝼㝻㝺㝹㝸㝷㝶㝵㝴㝳㝲㝱㝰㝯㝮㝭㝬㝫㝪㝩㝨㝧㝦㝥㝤㝣㝢㝡㝠㝟㝞㝝㝜㝛㝚㝙㝘㝗㝖㝕㝔㝓㝒㝑㝐㝏㝎㝍㝌㝋㝊㝉㝈㝇㝆㝅㝄㝃㝂㝁㝀㜿㜾㜽㜼㜻㜺㜹㜸㜷㜶㜵㜴㜳㜲㜱㜰㜯㜮㜭㜬㜫㜪㜩㜨㜧㜦㜥㜤㜣㜢㜡㜠㜟㜞㜝㜜㜛㜚㜙㜘㜗㜖㜕㜔㜓㜒㜑㜐㜏㜎㜍㜌㜋㜊㜉㜈㜇㜆㜅㜄㜃㜂㜁㜀㛿㛾㛽㛼㛻㛺㛹㛸㛷㛶㛵㛴㛳㛲㛱㛰㛯㛮㛭㛬㛫㛪㛩㛨㛧㛦㛥㛤㛣㛢㛡㛠㛟㛞㛝㛜㛛㛚㛙㛘㛗㛖㛕㛔㛓㛒㛑㛐㛏㛎㛍㛌㛋㛊㛉㛈㛇㛆㛅㛄㛃㛂㛁㛀㚿㚾㚽㚼㚻㚺㚹㚸㚷㚶㚵㚴㚳㚲㚱㚰㚯㚮㚭㚬㚫㚪㚩㚨㚧㚦㚥㚤㚣㚢㚡㚠㚟㚞㚝㚜㚛㚚㚙㚘㚗㚖㚕㚔㚓㚒㚑㚐㚏㚎㚍㚌㚋㚊㚉㚈㚇㚆㚅㚄㚃㚂㚁㚀㙿㙾㙽㙼㙻㙺㙹㙸㙷㙶㙵㙴㙳㙲㙱㙰㙯㙮㙭㙬㙫㙪㙩㙨㙧㙦㙥㙤㙣㙢㙡㙠㙟㙞㙝㙜㙛㙚㙙㙘㙗㙖㙕㙔㙓㙒㙑㙐㙏㙎㙍㙌㙋㙊㙉㙈㙇㙆㙅㙄㙃㙂㙁㙀㘿㘾㘽㘼㘻㘺㘹㘸㘷㘶㘵㘴㘳㘲㘱㘰㘯㘮㘭㘬㘫㘪㘩㘨㘧㘦㘥㘤㘣㘢㘡㘠㘟㘞㘝㘜㘛㘚㘙㘘㘗㘖㘕㘔㘓㘒㘑㘐㘏㘎㘍㘌㘋㘊㘉㘈㘇㘆㘅㘄㘃㘂㘁㘀㗿㗾㗽㗼㗻㗺㗹㗸㗷㗶㗵㗴㗳㗲㗱㗰㗯㗮㗭㗬㗫㗪㗩㗨㗧㗦㗥㗤㗣㗢㗡㗠㗟㗞㗝㗜㗛㗚㗙㗘㗗㗖㗕㗔㗓㗒㗑㗐㗏㗎㗍㗌㗋㗊㗉㗈㗇㗆㗅㗄㗃㗂㗁㗀㖿㖾㖽㖼㖻㖺㖹㖸㖷㖶㖵㖴㖳㖲㖱㖰㖯㖮㖭㖬㖫㖪㖩㖨㖧㖦㖥㖤㖣㖢㖡㖠㖟㖞㖝㖜㖛㖚㖙㖘㖗㖖㖕㖔㖓㖒㖑㖐㖏㖎㖍㖌㖋㖊㖉㖈㖇㖆㖅㖄㖃㖂㖁㖀㕿㕾㕽㕼㕻㕺㕹㕸㕷㕶㕵㕴㕳㕲㕱㕰㕯㕮㕭㕬㕫㕪㕩㕨㕧㕦㕥㕤㕣㕢㕡㕠㕟㕞㕝㕜㕛㕚㕙㕘㕗㕖㕕㕔㕓㕒㕑㕐㕏㕎㕍㕌㕋㕊㕉㕈㕇㕆㕅㕄㕃㕂㕁㕀㔿㔾㔽㔼㔻㔺㔹㔸㔷㔶㔵㔴㔳㔲㔱㔰㔯㔮㔭㔬㔫㔪㔩㔨㔧㔦㔥㔤㔣㔢㔡㔠㔟㔞㔝㔜㔛㔚㔙㔘㔗㔖㔕㔔㔓㔒㔑㔐㔏㔎㔍㔌㔋㔊㔉㔈㔇㔆㔅㔄㔃㔂㔁㔀㓿㓾㓽㓼㓻㓺㓹㓸㓷㓶㓵㓴㓳㓲㓱㓰㓯㓮㓭㓬㓫㓪㓩㓨㓧㓦㓥㓤㓣㓢㓡㓠㓟㓞㓝㓜㓛㓚㓙㓘㓗㓖㓕㓔㓓㓒㓑㓐㓏㓎㓍㓌㓋㓊㓉㓈㓇㓆㓅㓄㓃㓂㓁㓀㒿㒾㒽㒼"_${\(_3$#2$,m!*X+:X;@^}hX  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


so:

  N=8
S=6
L=13


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

• This is a standard loophole: meta.codegolf.stackexchange.com/a/1789/16294 Commented May 4, 2015 at 19:04
• Ok .. reworked it .. hopefully no loop holes this time ? Commented May 4, 2015 at 19:44
• You have to print all numbers from 1 to N. With your list, you can't print 11`. Commented May 4, 2015 at 19:47
• Yeah, just noticed that as well :) lol ... tricky .. (oh well, going to leave this her and let it sink ... sigh ... ) :) Commented May 4, 2015 at 19:47
• 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. Commented May 4, 2015 at 21:07