Write a rectangular block of text that when arranged into a Sierpinski carpet, using same-sized blocks of spaces for the empty portions, creates a program that outputs the iteration number of the carpet.
For example, if your text block is
TXT
BLK
then running the program
TXTTXTTXT
BLKBLKBLK
TXT TXT
BLK BLK
TXTTXTTXT
BLKBLKBLK
should output 1
because the shape of the program represents the first iteration of the Sierpinski carpet.
Similarly, running
TXTTXTTXTTXTTXTTXTTXTTXTTXT
BLKBLKBLKBLKBLKBLKBLKBLKBLK
TXT TXTTXT TXTTXT TXT
BLK BLKBLK BLKBLK BLK
TXTTXTTXTTXTTXTTXTTXTTXTTXT
BLKBLKBLKBLKBLKBLKBLKBLKBLK
TXTTXTTXT TXTTXTTXT
BLKBLKBLK BLKBLKBLK
TXT TXT TXT TXT
BLK BLK BLK BLK
TXTTXTTXT TXTTXTTXT
BLKBLKBLK BLKBLKBLK
TXTTXTTXTTXTTXTTXTTXTTXTTXT
BLKBLKBLKBLKBLKBLKBLKBLKBLK
TXT TXTTXT TXTTXT TXT
BLK BLKBLK BLKBLK BLK
TXTTXTTXTTXTTXTTXTTXTTXTTXT
BLKBLKBLKBLKBLKBLKBLKBLKBLK
should output 2 because this is the shape of the second Sierpinski carpet iteration.
Running the text block as is
TXT
BLK
should output 0
because it can be considered the zeroth iteration.
This should work for all further iterations. (At least theoretically, assuming the computer has the memory and all.)
Details
- Programs may not read or access information about their source code. Treat this like a strict quine challenge.
- Output goes to stdout or similar alternative. Only output the number and an optional trailing newline. There is no input.
- The text block may contain any characters that are not considered line terminators. The text block may contain spaces.
- The "empty space" in the carpet must consist entirely of space characters.
- You may optionally assume all the programs have a trailing newline.
You can use this stack snippet to generate a carpet for a given text block at any iteration:
<style>#o,#i{font-family:monospace;}</style><script>function c(e){e=e.split("\n");for(var n=new Array(3*e.length),t=0;t<n.length;t++){var l=t%e.length;n[t]=e[l]+(t>=e.length&&t<2*e.length?e[l].replace(/./g," "):e[l])+e[l]}return n.join("\n")}function f(){for(i=document.getElementById("i").value,n=parseInt(document.getElementById("n").value);n>0;)i=c(i),n--;document.getElementById("o").value=i}</script><textarea id='i'placeholder='code block...'rows='8'cols='32'></textarea><br>Iterations <input id='n'type='text' value='1'><br><br><button type='button'onclick='f()'>Generate</button><br><br><textarea id='o'placeholder='output...'rows='8'cols='32'style='background-color:#eee'readonly></textarea>
Scoring
The submission whose initial text block is smallest by area (width times height) is the winner. The TXT\nBLK
example is 3 by 2 for a score of 6. (Basically the shortest code wins, hence the code-golf tag.)
Tiebreaker goes to the submission that uses the fewest distinct characters in their text block. If still tied, answer posted first wins.