# Prolific Perfect Pangram Programs Pertaining to Printable ASCII

Updates: Time limit removed. You must be able to describe output - see new rule.

A pangram is a sentence that uses every letter in the alphabet at least once, such as:

The quick brown fox jumps over the lazy dog.

A perfect pangram uses every letter exactly once.

Consider writing a program that is a perfect pangram, using the 95 printable ASCII characters (hex codes 20 to 7E) as the alphabet:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~  Such a program must contain exactly 95 characters, with each printable ASCII character occurring exactly once, but in any order. (Thus there are 95! = 1.03×10148 possibilities.) Your task is to write this program such that the number of printable ASCII characters printed to stdout is as high as possible (i.e. prolific). Your score is the number of printable ASCII characters your program outputs (the total amount, not the distinct amount: AABC scores 4 whereas ABC scores 3). The highest score wins. # Details • The output may contain any characters (including duplicates) but only instances of the 95 printable ASCII characters count towards your score. • You can use this JSFiddle to count the number of printable ASCII characters in any string. • If your language does not have stdout use the most appropriate alternative. • Your program... • must have finite runtime (the time limit has been removed) • must have finite output • may contain comments • must compile and run without (uncaught) errors • must not prompt for or require input • must be time invariant and deterministic • must not use external libraries • must not require a network connection • must not make use of external files • (you may use the program file itself as long as changing the file name does not alter the program's behavior) • If this task is impossible is some language that's just too bad. • You must give your exact output or precisely describe it if it is too large to fit in a post. You do not actually have to run your program. As long as it would run in a finite amount of time on a computer with an unbounded amount of memory it is valid. # Example This simplistic Python 2 program is a possible solution: print 9876543210#!"$%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghjklmoqsuvwxyz{|}~


It outputs 9876543210 which contains 10 printable ASCII characters, thus scoring 10.

• As amazingly admirable as alliteration appears, pangrams just pack a powerful punch, as they're quite vexing. – Geobits Oct 10 '14 at 1:36
• I just reread the total-not-distinct rule too. I'd skimmed over it earlier, concluding it was obviously a distinct-not-total rule since the alternative would lead to absurd constructions such as printing the letter a six quadrillion times, where it isn't even possible to obtain an accurate upper limit on character count. Anyway, I'm still proud of my 95, even if it is kind of small. Size isn't everything, you know. – COTO Oct 10 '14 at 5:50
• Why do you think this task is impossible in HQ9+? – Peter Taylor Oct 10 '14 at 8:24
• I'm going to try and do this in FORTRAN (so I can make use of the case insensitivity). --- AND scratch that. I need the letter O 4 times: 2 times for the program declaration and 2 times for my loop declaration. – Nzall Oct 10 '14 at 9:55
• @Dennis No. 5more – Calvin's Hobbies Oct 11 '14 at 16:03

# GolfScript, over 2↑↑↑(9871↑↑2) chars

2 9871.?,{;0$[45)63]n+*~}/ #!"%&'(-:<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_abcdefghijklmopqrstuvwxyz|  Prints an integer. Take advantage of unlimited CPU register size (which determines the maximum string length in Ruby), memory and run time. The linefeed is solely for readability. ### The code 2 # Push 2. 9871.? # Push b := 9871↑↑2 = 9871↑9871 = 9871**9871. ,{ # For each i from 0 to b - 1: ;0$         #   Discard i and duplicate the integer on the stack.
[45)63]n+*  #   Replicate ".?\n" that many times.
~           #   Evaluate.
}/           #


### The score

Define b = 9871↑↑2 (see Knuth's up-arrow notation).

• .? executes f : x ↦ x↑x.

• The inner block executes g : x ↦ fx(x).

Since f(x) = x↑x = x↑↑2, f2(x) = (x↑x)↑(x↑x) > x↑x↑x = x↑↑3,
f3(x) = ((x↑x)↑(x↑x))↑((x↑x)↑(x↑x)) > (x↑x↑x)↑(x↑x↑x) > x↑x↑x↑x = x↑↑4 and so forth, we have
g(x) > x↑↑(x+1) > x↑↑x.

• The outer block executes h : x ↦ gb(x).

Since g(x) = x↑↑x = x↑↑↑2, g2(x) = (x↑↑x)↑↑(x↑↑x) > x↑↑x↑↑x = x↑↑↑3,
g3(x) = ((x↑↑x)↑↑(x↑↑x))↑↑((x↑↑x)↑↑(x↑↑x)) > (x↑↑x↑↑x)↑(x↑↑x↑↑x) > x↑↑x↑↑x↑↑x = x↑↑↑4 and so forth, we have h(x) > x↑↑↑(b+1).

• We start with the integer 2 on the stack, so the code calculates h(2) > 2↑↑↑(b+1).

• The score is the number of decimal digits of h(2), which is log(h(2)) + 1 > log(2↑↑↑(b+1)) > 2↑↑↑b.

Thus, the score is larger than 2↑↑↑(9871↑↑2).

2↑↑↑n grows at a ridiculous pace as n gets larger. 2↑↑↑4 := 2↑↑2↑↑2↑↑2 = 2↑↑2↑↑4 = 2↑↑65536, which is a right-associative power tower of 65536 copies of 2:

Similarly, 2↑↑↑5 := 2↑↑(2↑↑↑4), which is a power tower of 2↑↑↑4 copies of 2.

Now, the score isn't 2↑↑↑4 or 2↑↑↑5, it's larger than 2↑↑↑b, where b > 2 × 1039 428. That's a big number...

• @DigitalTrauma - You should check mine ;) – Optimizer Oct 10 '14 at 21:46
• @Dennis - How much is it roughly ? – Optimizer Oct 10 '14 at 21:54
• @Optimizer You got me ;-) – Digital Trauma Oct 10 '14 at 22:01
• Awesome! It reminds me of Graham's number... That is big! – rewritten Oct 11 '14 at 7:24
• Note that, while this theoretically should print a very large number of zeros, in practice it just crashes the interpreter with in *': bignum too big to convert into long' (RangeError). – Ilmari Karonen Oct 11 '14 at 11:56

# Perl, 70*18446744073709551615*10^987654320

say q{!"#%&'+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\]^_bcdfghijklmnoprtuvwz|}x(1e987654320*~$[)  Output: !"#%&'+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\]^_bcdfghijklmnoprtuvwz|  repeated 18446744073709551615*10^987654320 times. $[ is by default 0, so ~$[ is equivalent to 18446744073709551615. As a side note, I ran out of memory trying to create the number 10^987654320. ## Old Answer (7703703696): say qw(!"#$%&'*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_bcdefghijklmnoprtuvz{|}~10)x98765432


Output is:

!"#$%&'*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_bcdefghijklmnoprtuvz{|}~10  repeated 98765432 times. Note: Run all samples with perl -Mbignum -E • nice! but I wonder if one could use recursivity... (not possible to call oneself if you have to use your own name, as it would repeath the characters in the name... but couldn't your function name end up in$_ or another of Perl's variables?).. or use $0 calls cleverly (without filling the heap) – Olivier Dulac Oct 10 '14 at 15:48 • If you had enough memory, you could do perl -E'say qw{m}x(9876543210*ord$")' – hmatt1 Oct 10 '14 at 16:34
• If it helps there is no longer a time or memory limit. – Calvin's Hobbies Oct 10 '14 at 20:34
• It's unfortunate that Perl uses ** rather than ^ for exponentiation. – Mark Oct 12 '14 at 9:38

seq 9E15;#\!%*+,-./2346780:=@ABCDFGHIJKLMNOPQRSTUVWXYZ]^_abcdfghijklmnoprtuvwxyz~"'$&()?<>{}|[  Outputs integers 1 to 9x1015, one per line. Takes a long time. Why 9E15? It turns out that GNU seq appears to use 64-bit floats (double) internally. The largest whole number we can represent with this type, before increment by one stops working due to lack of precision, is 253 or 9007199254740992. The closest we can get to this with exponential notation is 9E15 or 9000000000000000. To calculate the score, I am using adding up all the numbers with a given number of digits and adding 9E15, because there is a newline between each number: 8000000000000001*16 + 900000000000000*15 + 90000000000000*14 + 9000000000000*13 + 900000000000*12 + 90000000000*11 + 9000000000*10 + 900000000*9 + 90000000*8 + 9000000*7 + 900000*6 + 90000*5 + 9000*4 + 900*3 + 90*2 + 9 + 9000000000000000  I could pipe this output through od for an extra order of magnitude or so, but that makes the score calculation much harder. Pre-rule change answer: # Bash+coreutils, 18,926,221,380 seq 1592346780;#\!%*+,-./:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ]^_abcdfghijklmnoprtuvwxyz~"'$&()?<>{}|[


Outputs 1 to 1592346780. On my mid 2012 macbook (which is not that far off the linked benchmark), this takes about 9m45s.

I couldn't resist optimizing it a bit more, even though its probably meaningless.

### Output:

$time ./pangram.sh | wc 1592346780 1592346780 18926221380 real 9m46.564s user 11m7.419s sys 0m10.974s$

• why aren't you doing seq 9876543210;? – durron597 Oct 10 '14 at 17:14
• @durron597 Because that takes too long - probably about an hour. It needs to complete in under 10 minutes. – Digital Trauma Oct 10 '14 at 17:14
• but surely the only limiting factor of this program is i/o... any other program in any other language could not really beat this. – durron597 Oct 10 '14 at 17:17
• @durron597 Yes, I think that is right. Though I wouldn't be surprised if someone in this community finds a clever way... – Digital Trauma Oct 10 '14 at 17:21
• @DigitalTrauma I'm actually removing the time limit to ensure this is not the penultimate answer (no offense I just don't want the contest to be over so soon :P), so feel free to use 9876543210. You may want to read the new last rule. – Calvin's Hobbies Oct 10 '14 at 17:39

## GolfScript, ≈ 3*10^(2*10^7) i.e. ≈ 3x1020000000

 87 9654321?,0${;.p}/#!"%&'()*+-9:<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnoqrstuvwxyz|~  How it works 87 9654321? "Pushes 87^9654321 to stack"; , "Pushes an array [0, 1, 2 ... (87^9654321) - 1] to stack";  "Creates a string representation of the array like "[0 1 2...]"; 0$            "Copies the string";
{;.p}/      "Print the string wrapped in quotes X times";
#...  "This is all comment";


Here X is the character count (length) of the string representation of the array [0, 1, 2..,(87^9654321) - 1] which will be like [0 1 2 3 4 ... (87^9654321) - 1]

I am trying to calculate X here so as to find my score. (87^9654321) - 1 is roughly 10^(10^7.272415829713899) with 18724742 decimal digits.

X is roughly 3*10^(2*10^7) so X*X is also same only. Note that these values are on a very lower side as due to computation limitations of (even) wolframa, I was not able to compute sum (floor(log10(x)) + 1) for x = 1 to (87^9654321 - 1) which is the true value of X

• In theory, there would be a few ways of making this even hewuger, but sadly Ruby's BigNum does have limits and 87 9654321? is just Infinity. – Dennis Oct 10 '14 at 20:55
• Oh! ? Do you know the maximum ? ;) – Optimizer Oct 10 '14 at 21:00
• Not exactly. Seems to depend on the machine, since the integer has to fit into RAM. With unbounded memory, I don't know where the limit would be. Probably 2**(2**64)-1 for 64-bit Ruby. – Dennis Oct 10 '14 at 21:13
• We have unbounded amount of RAM – Optimizer Oct 10 '14 at 21:16
• Yes, that's why I clarified. For CJam, there's a fixed limit and the interpreter just crashes when you exhaust the memory. Ruby seems to be different. – Dennis Oct 10 '14 at 21:19

# MATLAB, 95

Code

char(37-5:126)% !"#$&'*+,./0489;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_bdefgijklmnopqstuvwxyz{|}~  Output  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~


Output contains all specified ASCII characters, each exactly once, and in order.

• Note to viewers: This answer was submitted when the spec asked to maximize unique characters. This is no longer the goal, but it's ok if this answer stays since it is valid. – Calvin's Hobbies Oct 10 '14 at 16:55

# Ruby, 89

p %q{!"#$&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnorstuvwxyz|~}  Output: "!\"\#$&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnorstuvwxyz|~"


Contains all ASCII characters except, p, , %, q, {, and }.

• Note to viewers: This answer was submitted when the spec asked to maximize unique characters. This is no longer the goal, but it's ok if this answer stays since it is valid. – Calvin's Hobbies Oct 10 '14 at 16:56

# GolfScript, 93

{ !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz|~}  Output: { !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz|~}
}


Contains all ASCII characters except " and '.

• You're program isn't a perfect pangram though, is it? It doesn't seem to contain " or ' either. – Martin Ender Oct 10 '14 at 9:01
• Note to viewers: This answer was submitted when the spec asked to maximize unique characters. This is no longer the goal, but it's ok if this answer stays if it made valid. – Calvin's Hobbies Oct 10 '14 at 16:57
• It's easy enough to make this valid under the new rules: just remove # from its current position and append #"' to the end. The score will drop by one, though. – Ilmari Karonen Oct 11 '14 at 11:50

# Golfscript - 27*265439870

This my first Golfscript submission! :)

12,{.+}6543 9870?*#!"\$%&'()-/:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz|~


Explanation:

12,                     - Creates an array of ascending numbers from 0 to 11
                    - Converts the array to a string
{.+}                - Duplicates the string on the stack and concatenates the two
6543 9870?      - Calculates 6543^9870 and pushes it to the stack
*     - Repeat the block 6543^9870 times
#... - The rest is a comment


The output is a load of lists of numbers. Consider the following code:

12,{.+}1*


With 12, it produces the following array:

[0 1 2 3 4 5 6 7 8 9 10 11]


The backtick turns that into a string, passing it to the block {.+}. This duplicates the string and then concatenates the two, producing:

[0 1 2 3 4 5 6 7 8 9 10 11][0 1 2 3 4 5 6 7 8 9 10 11]


The 1* tells the interpreter to execute the previous block one time (21 = 2).

So, based upon that:

 12,{.+}n*


Outputs the output of 12, 2n times.