Princely Prefix by a Program in Pattern

16

2

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,/,*}:

abcd
bcd*
*/ac

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)

    print('O\
    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.

randomra

Posted 2015-04-28T12:18:49.137

Reputation: 19 909

Doesn't this limit the program size to 26x26 at most? – marinus – 2015-04-28T12:35:20.763

@marinus Yes it does. – randomra – 2015-04-28T12:35:51.600

Are you sure this is solvable? – FUZxxl – 2015-04-28T13:16:25.307

@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). – Martin Ender – 2015-04-28T13:17:48.167

@MartinBüttner Ah! I forgot about the “a prefix of...” part. – FUZxxl – 2015-04-28T13:19:03.033

by "prefix" you mean that the words must be in order, starting from the beginning? – sirpercival – 2015-04-28T14:49:59.063

I don't think anyone will get the whole thing. There are information density concerns, even if you could use all 626 characters to encode it. I predict someone will do some clever compression into a ~16 character codeset, and get maybe 400 characters of output. – Sparr – 2015-04-28T17:28:08.710

Answers

4

CJam, 47

"Once wh
en Imwas
msix yea
r2s oldm
I "N-'m/
Sc*2s-O"
saw"N/SO
o'aS"m2 
a"Oo2s-N
-S/OI*so
'yI-a"nr
wiNadI"c
cel'iaIS
/m2*Oo'x
 I-scel*
Ooel'c 2
2/'e*ON-

Try it online

Alphabet: "'*-/2INOSacdehilmnorswxy

Explanation:

"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
"m2 
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"
"nr
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)

aditsu quit because SE is EVIL

Posted 2015-04-28T12:18:49.137

Reputation: 22 326

7

Pip, score = 38

eyli:
"Once
when0
I was
si01x
year5
old I
0sMw1
1M 0"
X1RMh
Rnsxy
iR:'M
'aiR 
:5'si

Alphabet: "'015:IMORXacdehilnorswxy

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

Explanation:

eyl      Statements consisting of single variables are no-ops
i:       Assign to i the following:
"Once
when0
I was
si01x
year5
old I
0sMw1
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

DLosc

Posted 2015-04-28T12:18:49.137

Reputation: 21 213

4

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:

x=chr 
print(
"Once\
 when"
,x(73)
)#prin

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

 "#(),37=O\cehinprtwx

Output is:

Once when I

Blckknght

Posted 2015-04-28T12:18:49.137

Reputation: 701

Note that this is valid in Python 2 also. Grats on finding a good answer. – mbomb007 – 2015-05-06T20:04:22.833

3

CJam, score = 21

"Once wh
en I"N-o
N;S"was 
six y"N-

Alphabet: -;INOSacehinoswxy

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

Ypnypn

Posted 2015-04-28T12:18:49.137

Reputation: 10 485

2

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:

 79c32"*)+#,105468:;=>Ibef
,:=>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.

Explanation

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

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

Sp3000

Posted 2015-04-28T12:18:49.137

Reputation: 58 729

1

Python 2, score = 13 (invalid)

Python isn't the best language for this.... Upon further inspection, there are two ns in my first line. There is no worthwhile remedy, and I'm going to stop wasting my time with Python. I'm currently working on making a solution in another language, but will not share which one yet.

print"Once wh\
en I",#Oncehtp
chr(0167)#Onwt

Alphabet (22): "#(),0167IOcehinprtw

Output: Once when I w

mbomb007

Posted 2015-04-28T12:18:49.137

Reputation: 21 944

Your first line is invalid, since it has two ns. This problem is nearly impossible in Python, since you can only use a line continuation backslash once (since the backslash needs to be in the last column) and no line can have two of the same kind of quotation mark. – Blckknght – 2015-05-01T21:03:51.897

@Blckknght Ah, I missed that one. Yeah. My answer would probably not be better than the OP's example then... – mbomb007 – 2015-05-01T21:28:49.277