You should write a program or function which outputs or returns as much of Chapter I of The Little Prince as it can. Your program or function has to be an M-by-N block of code containing only printable ascii characters (codepoint from 32 to 126) and newlines at the end of each row.

You can only use at most 26 characters of your choosing from the 96 printable ascii characters (and the newlines at the end of the rows).

In each row and column every character has to be distinct similar to a sudoku puzzle i.e. there can't be a letter in a row or column twice.

A correct example codeblock with M = 4, N = 3 and alphabet = {a,b,c,d,/,*}:


Code details

  • You can choose the shape of your code-block (i.e. M and N).
  • The block has to be filled with characters entirely i.e. every row has to have the same length.
  • A trailing newline at the end of the last row is optional.
  • As written above in each row and column every character has to be distinct.

Output details

  • You should output or return a prefix of Chapter I of The Little Prince without any additional output.
  • If you reach a newline in the text you can represent it as any common variant (\r,\n,\r\n) but use only one of them and count it as 1 byte to the score.
  • An extra trailing newline is optional.

Your score is the length of the output text excluding an additional newline if present. Higher score is better.

Example answer

##Python3, score = 6

alphabet = `print('O\ce w)#X` (alphabet element count = 16)

    nce w')#X

You can check the validity of your code with this Python 3 (ideone) program or this CJam program (online) provided by @MartinBüttner.

  • \$\begingroup\$ Doesn't this limit the program size to 26x26 at most? \$\endgroup\$
    – marinus
    Commented Apr 28, 2015 at 12:35
  • \$\begingroup\$ @marinus Yes it does. \$\endgroup\$
    – randomra
    Commented Apr 28, 2015 at 12:35
  • \$\begingroup\$ Are you sure this is solvable? \$\endgroup\$
    – FUZxxl
    Commented Apr 28, 2015 at 13:16
  • \$\begingroup\$ @FUZxxl the question contains a reference solution with score 6. Hopefully the question is designed such that it's not possible to print the entire thing (or it would need a tie breaker). \$\endgroup\$ Commented Apr 28, 2015 at 13:17
  • \$\begingroup\$ @MartinBüttner Ah! I forgot about the “a prefix of...” part. \$\endgroup\$
    – FUZxxl
    Commented Apr 28, 2015 at 13:19

5 Answers 5


Pip, score = 38

I was
old I
1M 0"

Alphabet: "'015:IMORXacdehilnorswxy

(I sure would hate to try this in a real programming language.)


eyl      Statements consisting of single variables are no-ops
i:       Assign to i the following:
I was
old I
1M 0"    ...this string
X1       ...repeated once (no-op to get alignment right)
RMh      ...with all 1s and 0s removed (h is preinitialized to 100)
Rns      ...and all newlines replaced with spaces.
xy       More no-ops
iR:'M'a  Replace every M with a, assigning result back to i
iR:5's   Replace every 5 with s, assigning result back to i
i        Auto-print i

CJam, 47

"Once wh
en Imwas
msix yea
r2s oldm
I "N-'m/
Ooel'c 2

Try it online

Alphabet: "'*-/2INOSacdehilmnorswxy


"Once wh
en Imwas
msix yea
r2s oldm
I "         push this string
N-          remove newlines
'm/Sc*      replace m's with spaces (the c is redundant)
2s-         convert 2 to string and remove 2's
O           push an empty string
saw"        push this string
N/          split into lines (effectively removes the newline)
S           push a space
Oo          print empty string (no-op)
'a          push 'a'
S           push a space
a"          push this string
Oo          print empty string (no-op)
2s-         convert 2 to string and remove 2's
N-          remove newline
S/          split by space (effectively removes the space)
OI*so       print an empty string repeated 18 times (no-op)
'y          push 'y'
I-          subtract 18 -> 'g'
a           wrap in array (string) -> "g"
wiNadI"     push this string
c           convert to (first) character -> 'n'
c           convert to character (no-op)
el          convert to lowercase (no-op)
'i          push 'i'
a           wrap in array (string) -> "i"
IS/         split " " into slices of length 18 -> [" "]
m           (acting as -) remove space strings from "i" (no-op)
2*          repeat "i" 2 times -> "ii"
Oo          print empty string (no-op)
'x          push 'x'
I-          subtract 18 -> 'f'
sc          convert to string and back to char (no-op)
el          convert to lowercase (no-op)
*           join "ii" with separator 'f' -> "ifi"
Oo          print empty string (no-op)
el          convert to lowercase (no-op)
'c          push 'c'
2 2/        divide 2 by 2 -> 1
'e          push 'e'
*           repeat 'e' 1 time -> "e"
O           push empty string
N-          remove newlines (no-op)
  • \$\begingroup\$ The "try it online" link doesn't work. It just prints "hi" \$\endgroup\$
    – mbomb007
    Commented 2 days ago

Python 3, score=11

This is a really tough problem for Python, as the restrictions on repeating characters on a line or column make it nearly impossible to make more than one string literal. The various ways of joining strings together are thus fairly useless, since you can't get the strings to start with in any useful way. Here's my best attempt:


Note that there is a space at the end of the first line. The alias x for chr is necessary to avoid the same character ending up in more than one column. The comment characters at the end could be almost anything.

The alphabet is 21 printable characters, plus newline (note the space at the start):


Output is:

Once when I

  • \$\begingroup\$ Note that this is valid in Python 2 also. Grats on finding a good answer. \$\endgroup\$
    – mbomb007
    Commented May 6, 2015 at 20:04

CJam, score = 21

"Once wh
en I"N-o
six y"N-

Alphabet: -;INOSacehinoswxy

Just to get the ball rolling; this can probably be beaten easily.


CJam, score = 15

I've had this idea for a while now but I haven't had time to sit down and shuffle things around until I get the needed column uniqueness, so here's a baby version for now:

,:=>Ibcef";7 6)#*219435+80
50I=>;9)6#*127438+ ":,bcfe
),68:>=Ibcef";20 5#*17394+
6)4*b123,97>:c"80f5=+;e# I
"9>+f=e# ),*0481362bI:;5c7

Alphabet (26): " #)*+,0123456789:;=>Ibcef

Try it online.


The basic idea is to make use of base encoding so we can print more than 26 types of chars. The core code is

79c                             e#  Push "O"
85032995607801617394 28b        e#  Push array of indices, encoding using base 28
123,97>:c" I                    e#  Push "abcdefghijklmnopqrstuvwxyz I\n"
f=                              e#  Map indices to chars

Note that we treat the first "O" for "Once" separately because including it in our string would take too much of our alphabet. If we wanted to we could try extended our indexing string, but since no more uppercase characters happen for a while apart from "I" I didn't bother too much with this.

We then need to build the big number on the second line somehow. The approach I took was to repeatedly multiply by some power, then add a constant, and repeat, so in the above code 85032995607801617394 is replaced by

7 6) # * 219435 +
9) 6 # * 127438 +
20 5 # * 17394 +

where ) is increment and # is exponentiation in CJam.

Then the rest (the most annoying part) is padding each row to fulfill the column criteria. To do this we dump chars in strings and use ; to pop them. Unfortunately, while we would very much like to use e# for comments as well to make things easier, the fact that # is exponentiation forbids this, so this is only done on the last line.

I'm fairly certain this method can be extended up until the comma in the first sentence, but unfortunately shuffling things around to meet the column criteria is proving difficult, so I might need another method of generating the base-encoded integer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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