21
Here's a pixelated 5 by 7 font for the digits 0 through 9:
.███.
█...█
█...█
█...█
█...█
█...█
.███.
..█..
███..
..█..
..█..
..█..
..█..
█████
.███.
█...█
....█
...█.
..█..
.█...
█████
.███.
█...█
....█
..██.
....█
█...█
.███.
█..█.
█..█.
█..█.
█████
...█.
...█.
...█.
█████
█....
█....
.███.
....█
█...█
.███.
.███.
█...█
█....
████.
█...█
█...█
.███.
█████
....█
....█
...█.
...█.
..█..
..█..
.███.
█...█
█...█
.███.
█...█
█...█
.███.
.███.
█...█
█...█
.████
....█
█...█
.███.
(This font and this page will probably look better if you run this JavaScipt code in your browsers console or in the URL bar prefixed by javascript:
: $('#question pre,.answer pre').css('line-height',1)
.)
Write two equal sized rectangular blocks of text, one to represent the empty spaces (.
) in the font above, and one to represent the filled spaces (█
).
When these two text blocks are arranged into the same 5×7 pattern as one of the digits above, then the resulting large text block should be a program that prints that digit to stdout. This should work for all 10 digits.
For example, if your .
text block was
---
'''
and your █
text block was
ABC
123
then the program
---ABCABCABC---
'''123123123'''
ABC---------ABC
123'''''''''123
ABC---------ABC
123'''''''''123
ABC---------ABC
123'''''''''123
ABC---------ABC
123'''''''''123
ABC---------ABC
123'''''''''123
---ABCABCABC---
'''123123123'''
should output 0
. Similarly, the program
------ABC------
''''''123''''''
ABCABCABC------
123123123''''''
------ABC------
''''''123''''''
------ABC------
''''''123''''''
------ABC------
''''''123''''''
------ABC------
''''''123''''''
ABCABCABCABCABC
123123123123123
should output 1
, and so on up to the program for 9
.
You can use this stack snippet to make the digit shaped programs:
<style>textarea{font-family:monospace;}</style><script>function go(){var t=parseInt(document.getElementById("digit").value[0]);if(isNaN(t))return void alert("Invalid digit.");for(var e=document.getElementById("empty").value.split("\n"),n=document.getElementById("filled").value.split("\n"),l=[],o=0;o<7*e.length;o++){l[o]="";for(var d=0;5>d;d++)l[o]+=font[t][Math.floor(o/e.length)][d]?n[o%n.length]:e[o%e.length]}document.getElementById("output").value=l.join("\n")}font=[[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],[[0,0,1,0,0],[1,1,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1]],[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,1,1,1,1]],[[0,1,1,1,0],[1,0,0,0,1],[0,0,0,0,1],[0,0,1,1,0],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],[[1,0,0,1,0],[1,0,0,1,0],[1,0,0,1,0],[1,1,1,1,1],[0,0,0,1,0],[0,0,0,1,0],[0,0,0,1,0]],[[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[0,1,1,1,0],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],[[1,1,1,1,1],[0,0,0,0,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,0,1,0],[0,0,1,0,0],[0,0,1,0,0]],[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],[[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,1],[0,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]]]</script><textarea id='empty' rows='8' cols='32' placeholder='empty space text block...'></textarea><textarea id='filled' rows='8' cols='32' placeholder='filled space text block...'></textarea><br>Digit <input id='digit' type='text' value='0'> <button type='button' onclick='go()'>Generate</button><br><br><textarea id='output' rows='16' cols='64' placeholder='output...' style='background-color: #eee;' readonly></textarea>
Details
- None of the 10 large text block programs should require input. Only output the single digit plus an optional trailing newline. Output to stdout or a similar alternative.
- None of the programs may read or access their own source code. Treat this like a strict quine challenge.
- The text blocks may not be identical and must have nonzero dimensions.
- The text blocks may contain any characters except line terminators.
- The 10 programs must be full-fledged programs written in the same language, they are not REPL snippets. You may optionally add a trailing newline to all of them or none of them.
Scoring
Your score is the area (width times height) of one of your text blocks. (They are the same size so there's no point in counting both blocks.) The area of the example is 3 by 2, for a score of 6.
The lowest score wins. In case of ties, the highest-voted answer wins.
On your code, you can improve it a lot.
var t=parseInt(document.getElementById("digit").value[0]);if(isNaN(t))return void alert("Invalid digit.");
can be written asvar t=document.getElementById("digit").value[0]/1;if(t!=t)return void alert("Invalid digit.");
, which is the same but shorter. There are a few more things you can improve in it, but it does look great! – Ismael Miguel – 2015-03-03T15:08:29.7434@IsmaelMiguel TBH I put it through a JS minifier to get it on one line. It was never meant to be golfed. – Calvin's Hobbies – 2015-03-03T15:16:21.987
Oh, dude... That is a bit lazy... In a golfing question, you post a non-golfed code... But hey, I get it and I'm just saying this. You don't have to follow what I said. But it's a good thing to do. – Ismael Miguel – 2015-03-03T15:20:17.580
6@IsmaelMiguel I posted ungolfed utility code, which arguably should be as readable as possible so bugs are easier to spot. But really, as long as it works, the code size of the stack snippet has literally zero bearing on the outcome of the challenge. – Calvin's Hobbies – 2015-03-03T15:32:36.923
I know, and I get it. I was just trying to joke about it. Sadly, mission failed. But maybe next time. – Ismael Miguel – 2015-03-03T15:42:09.600
3
text blocks may not be identical
really? I want to see someone break this rule, by giving two identical codeblocks, which magically return different digits, when every number is exactly the same code ^^ – Falco – 2015-03-04T10:39:01.863This should be easy as pie with Marbellous. Sadly I don't know Marbellous :( – M.Herzkamp – 2015-03-04T15:17:17.800
@Falco I know, I know :P I just need to cover my bases. – Calvin's Hobbies – 2015-03-04T15:22:39.273