Write a square block of code that is N characters wide and N characters tall, for some positive integer N.
For instance, your N may be 5 and the block look like this:
ThisI
sMy5B
y5Cod
eBloc
kOkay
This block needs to behave as follows:
When the top row is extracted and run as a program, the exact text
row
needs to be printed to stdout.For example,
ThisI
would printrow
.When the left column is extracted and run as a program, the exact text
col
needs to be printed to stdout.For example,
Tsyek
would printcol
.When the main diagonal from the top left to the bottom right corners is extracted and run as a program, the exact text
dia
needs to be printed to stdout.For example,
TMCoy
would printdia
.When the entire block is run as a program, including the newlines (with an optional trailing newline), the exact text
blk
needs to be printed to stdout.For example,
ThisI sMy5B y5Cod eBloc kOkay
would print
blk
.
Details
- All four programs are run in the same programming language.
- The N2 characters in the original block may be anything but line terminators.
- If your language does not have an stdout, you may use another common output method. It must be the same method across all four programs.
The submission whose original block contains the fewest distinct characters (not counting newlines) wins. Tiebreaker goes to the submission with the smaller N.
-
\$\begingroup\$ Given that there's surely a solution in some two-symbol esoteric language, I think this will become a solution to squeeze that into the smallest N. \$\endgroup\$xnor– xnor2015年04月03日 23:30:56 +00:00Commented Apr 3, 2015 at 23:30
-
\$\begingroup\$ @xnor Probably. Though a 1-distinct Lenguage answer is not out of the realm of possibility. Still, this scoring method is more interesting than having smallest N win first. \$\endgroup\$Calvin's Hobbies– Calvin's Hobbies2015年04月03日 23:34:04 +00:00Commented Apr 3, 2015 at 23:34
-
\$\begingroup\$ How can Lenguage work given that the row and column programs have the same length? \$\endgroup\$xnor– xnor2015年04月03日 23:44:22 +00:00Commented Apr 3, 2015 at 23:44
-
\$\begingroup\$ @xnor Ah, you're right. It wouldn't work. \$\endgroup\$Calvin's Hobbies– Calvin's Hobbies2015年04月03日 23:47:05 +00:00Commented Apr 3, 2015 at 23:47
-
\$\begingroup\$ Can non-block programs also end with a trailing newline? \$\endgroup\$jimmy23013– jimmy230132015年04月06日 20:19:53 +00:00Commented Apr 6, 2015 at 20:19
8 Answers 8
CJam, (削除) 13 (削除ここまで) 12 unique characters, N = 5
"row"
cd;"a
oaiaa
l"aa;
"blk"
As straight forward as it gets
UPDATE : Converted space to a
(no-op in this case) as pointed out by Runner112
-
2\$\begingroup\$ Every space can be turned into a character like
a
to bring the unique character count down to 12, right? \$\endgroup\$Runer112– Runer1122015年04月06日 12:35:41 +00:00Commented Apr 6, 2015 at 12:35 -
\$\begingroup\$ @Runer112 Damn! Thanks for the tip! \$\endgroup\$Optimizer– Optimizer2015年04月06日 12:39:54 +00:00Commented Apr 6, 2015 at 12:39
Bash, 19 unique characters, N = 19
trap echo\ row exit
t=t trap exit
t=t echo blk
exit
=
t e
c
e h
c o
h
o d
i
c a
o
l
- The first row is
trap echo\ row exit
. This causesecho row
to be executed when the script exits (just the first line) - The first column is
ttt=t echo col
- The diagonal is
t=tt echo dia
- The full block works by canceling the EXIT handler set up in the first line, then
echo blk
then exits.
-
1\$\begingroup\$ You can use lowercase
exit
to reduce unique characters by 4. You can also move theexit
command to the next line and replace all the semicolons with spaces. \$\endgroup\$jimmy23013– jimmy230132015年04月06日 20:30:59 +00:00Commented Apr 6, 2015 at 20:30
><> (Fish), 3 unique characters (N = 2000)
The code uses 1
and -
to put arbitrary numbers on the stack and p
to (self-)modify the code based on the top 3 numbers on the stack.
E.g Putting a !
at position 0 0
would look like 003b*p
in normal><> and with p1-
it becomes 111-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1--11-11-p
.
After the modification the instruction pointer (IP) wraps around the code and runs the modified part. In the "block" case the IP is redirected for further modification (then reredirected back) to differ from the "row" case. In the "row" case the same two redirection happens but there is no code in between them so they have no effect.
The final generated codes for the 4 cases (omitting the unchanged p1-
parts):
row: "wor"\ooo;
column: "loc"ooo;
diagonal: "dia"ooo;
block: "wor"\"klb"ooo;
The code size is 4 MB and the code is accessible here. (There is no difficulty running it.)
The generator python3 program is accessible here.
><>, 14 unique characters, N = 10
"wor"\ooo;
"
l a k
o i l
c db
" "
o oo
o o o
o o o
; ; ;
Pretty straightforward in a 2D language. The only tricky part is that we need the \
to distinguish between row
and blk
.
-
\$\begingroup\$ randomra notes that
p1-
would give a three char solution, but it would be really annoying to generate (and probably won't win). \$\endgroup\$Sp3000– Sp30002015年04月04日 11:49:35 +00:00Commented Apr 4, 2015 at 11:49
Brainfuck, 2 unique characters, N = 378
With possible slight bending of rules.
The program is a tad large, so here's a link to it on Pastebin.
The row
, col
and dia
programs are straightforward. They simply increment the byte cell until the right ASCII code is reached and then outputs. If the letter has already passed, it increments until the cell overflows so it can start again at 0.
The blk
program is where the slight rule bending occurs. In order to print the "exact text blk
" as asked in the challenge, backspaces are used (ASCII code 8), which requires the displaying console/terminal to support it. Whenever errant values from the row
/col
/dia
programs are printed, I ensure they are removed by outputting a few backspace control codes. To simplify things, I've ensured that all errant values outputted at one point are part of the printable ASCII range.
C (gcc), 26 unique chars, N = 29
*w;main(){printf(w?w:"row");}
ww;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;/*;;;;;;;;;;;;;;;;;;;;;;;;
m;;m;;;;;;;;;;;;;;;;;;;;;;;;;
a;;;a;;;;;;;;;;;;;;;;;;;;;;;;
i;;;;i;;;;;;;;;;;;;;;;;;;;;;;
n;;;;;n;;;;;;;;;;;;;;;;;;;;;;
(;;;;;;(;;;;;;;;;;;;;;;;;;;;;
);;;;;;;);;;;;;;;;;;;;;;;;;;;
{;;;;;;;;{;;;;;;;;;;;;;;;;;;;
p;;;;;;;;;p;;;;;;;;;;;;;;;;;;
r;;;;;;;;;;r;;;;;;;;;;;;;;;;;
i;;;;;;;;;;;i;;;;;;;;;;;;;;;;
n;;;;;;;;;;;;n;;;;;;;;;;;;;;;
t;;;;;;;;;;;;;t;;;;;;;;;;;;;;
f;;;;;;;;;;;;;;f;;;;;;;;;;;;;
(;;;;;;;;;;;;;;;(;;;;;;;;;;;;
";;;;;;;;;;;;;;;;";;;;;;;;;;;
c;;;;;;;;;;;;;;;;;d;;;;;;;;;;
o;;;;;;;;;;;;;;;;;;i;;;;;;;;;
l;;;;;;;;;;;;;;;;;;;a;;;;;;;;
";;;;;;;;;;;;;;;;;;;;";;;;;;;
);;;;;;;;;;;;;;;;;;;;;);;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
};;;;;;;;;;;;;;;;;;;;;;;};;*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;*w="blk";
V (vim), 11 unique characters, N=6
irow␛␛
cdddd␛
o␛i␛␛␛
l␛␛a␛␛
␛kdd␛␛
␛iblk␛
lot of escapes here. N=5 might be achievable, but I can't see a way to do it without increasing the unique characters.
Ruby, 24 unique chars, N=17
trap(0){$><<:row}
rr=a=:blk;%;00000
a0a00000000000000
p00p0000000000000
(000(000000000000
00000000000000000
)00000)0000000000
{000000{000000000
0000000ドル00000000ドル
>00000000>0000000
<000000000<000000
<0000000000<00000
:00000000000:0000
c000000000000d000
o0000000000000i00
l;;trap(0){$><<a;
};000000000000;{}
Explore related questions
See similar questions with these tags.