6
\$\begingroup\$

The program must print the following block of text of LED numbers exactly.

+-----------------------------------------------------------------+
|                                                                 |
| 000   1 222 333 4 4 555 666 777 888 999 AAA B   CCC   D EEE FFF |
| 0 0   1   2   3 4 4 5   6     7 8 8 9 9 A A B   C     D E   F   |
| 0 0   1 222 333 444 555 666   7 888 999 AAA BBB C   DDD EEE FFF |
| 0 0   1 2     3   4   5 6 6   7 8 8   9 A A B B C   D D E   F   |
| 000   1 222 333   4 555 666   7 888 999 A A BBB CCC DDD EEE F   |
|                                                                 |
+-----------------------------------------------------------------+

Notice the 1-char padding inside the borders. The trailing newlines, and the types of the newlines are not significant. However, the whitespaces are the spaces you get when you press spacebars (ASCII 32).

Shortest code wins. Using data encoding (base64, gzip), or compressing with other Unicode characters is discouraged. You cannot use programs like cat or gzip since they are not programming languages.

The character count must be less than 600 to qualify.

\$\endgroup\$
10
  • \$\begingroup\$ There is m4 which is turing complete language, so this is still possible, and one char less than cat \$\endgroup\$
    – YOU
    Commented May 24, 2011 at 1:31
  • 3
    \$\begingroup\$ I always object to problems that have the form "solve this instance of a problem" rather than "write a program to solve any problem in this class". And if we make it general it becomes very similar to Code Golf - Banner Generation. \$\endgroup\$ Commented May 24, 2011 at 1:34
  • 5
    \$\begingroup\$ What do you mean by data encoding is discouraged? We can't use an array of encodings, say of a bit mapping of the characters to print from? \$\endgroup\$
    – mellamokb
    Commented May 24, 2011 at 3:17
  • 1
    \$\begingroup\$ This would have been far more interesting of a challenge if it had taken a number (hex? decimal?) on input and output it in that banner format. \$\endgroup\$ Commented May 28, 2011 at 23:21
  • 2
    \$\begingroup\$ The obvious solution is to count length in bytes after encoding with UTF-8 rather than counting characters. \$\endgroup\$ Commented May 31, 2011 at 19:11

8 Answers 8

7
\$\begingroup\$

Golfscript, 142 137 chars

Unfortunately some of the characters are control codes, so I'm going to have to post a hexdump and a link rather than a direct copy of the source:

00000000  27 2b 27 3a 28 27 2d 27  36 35 2a 3a 5e 28 6e 27  |'+':('-'65*:^(n'|
00000010  7c 27 3a 29 27 20 27 3a  7c 36 34 2a 3a 40 27 20  ||':)' ':|64*:@' |
00000020  7c 0a 7c 20 27 3a 76 5b  27 77 12 5d 5b 3a 6b 6f  ||.| ':v['w.][:ko|
00000030  52 7f 7b 7e 2f 65 1f 6d  6c 27 7b 7d 2f 5d 3a 24  |R.{~/e.ml'{}/]:$|
00000040  2c 2c 7b 3a 78 3b 5b 27  60 40 50 20 00 10 2c 08  |,,{:x;['`@P ..,.|
00000050  1a 04 00 02 05 01 03 27  7b 7d 2f 5d 7b 24 78 3d  |.......'{}/]{$x=|
00000060  26 21 5b 34 38 78 2e 31  30 2f 37 2a 2b 2b 5d 7c  |&![48x.10/7*++]||
00000070  2b 3d 7d 25 33 2f 7d 25  7a 69 70 7b 7c 2a 7d 25  |+=}%3/}%zip{|*}%|
00000080  76 2a 76 40 29 6e 28 5e  28                       |v*v@)n(^(|

leds.gs

Note that all of the characters are 7-bit values and legal Unicode code points, so the number of characters is the same as the number of bytes in UTF-8.

Basically there are two hard-coded arrays. The first is a 15-element bitmap indicating which of the 7 segments control each grid cell. The second is the 7-segment encoding of the 16 characters. Then it's just a case of using bitwise and to work out which segments are turned on and doing some string manipulation.

\$\endgroup\$
6
\$\begingroup\$

Python, 216 chars

S=' '
E='|\n| '
H=B='+'+'-'*65+'+\n|'+S*65+E
X='%(x)X'
M=[X+S+S,S+S+X,X+S+X,X+X+X]
for i in range(5):
 for n in range(16):H+=M[0xcf33ed703ec2bbdefbb55fb3dcd7addf37557ab>>10*n+2*i&3]%{'x':n}+S
 H+=E
print H+B[-6::-1]
\$\endgroup\$
4
  • 1
    \$\begingroup\$ You can kill 2 chars by replacing X+X+X with X*3. \$\endgroup\$
    – JPvdMerwe
    Commented May 29, 2011 at 12:28
  • 2
    \$\begingroup\$ Then you can also replace the for-loops with exec("H+=M[0xcf33ed703ec2bbdefbb55fb3dcd7addf37557ab>>10*n+2*i&3]%{'x':n}+S;n+=1;"*16+"n=0;H+=E;i+=1;")*5 to save another 3 characters. \$\endgroup\$
    – JPvdMerwe
    Commented May 29, 2011 at 12:47
  • \$\begingroup\$ @JPvdMerwe OMFG, that's an amazing shrink for Python... is there any chance you could apply this same technique in JavaScript loops? \$\endgroup\$ Commented Jul 18, 2014 at 1:40
  • \$\begingroup\$ @WallyWest, I don't know JS well enough, but if you can duplicate a string by multiplying it with an int then you should be able to. Otherwise, it would be highly unlikely to be useful as you'd have to assign a string duplication function to a var. \$\endgroup\$
    – JPvdMerwe
    Commented Jul 18, 2014 at 23:08
6
\$\begingroup\$

Java, 302 characters

class A{public static void main(String[]a){String d="w$]m.k{%o?zS|[#!% \" $ :(L 0 @ p` ",s="";for(int y=0;y<9;y++){s+=y%8==0?"+-":"| ";for(int x=0;x<64;x++)s+=y%8==0?"-":y!=1&&y!=7&&((d.charAt(8+x%4+y*4)-32)&d.charAt(x/4))>0?(char)((x<40?48:55)+x/4):" ";s+=y%8==0?"+\n":"|\n";}System.out.println(s);}}

Expanded :

public class A {
    public static void main(String[] args) {
        String d = "w$]m.k{%o?zS|[#!% \" $ :(L 0 @ p` ", s = "";
        for (int y = 0; y < 9; y++) {
            s += y % 8 == 0 ? "+-" : "| ";
            for (int x = 0; x < 64; x++)
                s += y % 8 == 0 ? "-" : 
                    y != 1 && y != 7 && ((d.charAt(8 + x % 4 + y * 4) - 32) & d.charAt(x / 4)) > 0 ? 
                            (char) ((x < 40 ? 48 : 55) + x / 4) : " ";
            s += y % 8 == 0 ? "+\n" : "|\n";
        }
        System.out.println(s);
    }
}

The digits shapes are encoded in a byte with the following pattern:

  1 1 1
2       4
2       4
2       4
  8 8 8
16      32
16      32
16      32
  646464

e.g number 5 is 1|2|8|32|64 = 107

When outputting the text, each "pixel" (character) is set only if some "lines" of digits are enabled. For example, the upper-left character of a digit is set only if the line 1 or 2 are enabled. The lower-down character is set only if lines 32 or 64 are enabled.

\$\endgroup\$
3
\$\begingroup\$

For the sheer fun of it...

BrainFuck 611

Note: Can probably be golfed further.

++[------>+<]>.++.................................................................--.>++++++++++.>--[-->+++<]>-.[---->+<]>+.................................................................-[->++++<]>.>++++++++++.>--[-->+++<]>-.[---->+<]>+.[-->+++<]>...[--->++<]>...[-->+++<]>+.-[--->++<]>.[-->+++<]>++...--[--->++<]>.++[-->+++<]>...[--->++<]>--.++[-->+++<]>+.-[--->++<]>--.++[-->+++<]>+.-[--->++<]>--.-----[->++<]>-...--[--->++<]>--.-----[->++<]>...[-->+<]>+++++.----[->++<]>-...+[-->+<]>++++.----[->++<]>...[-->+<]>++++.---[->++<]>-...+[-->+<]>+++.[->++<]>+...-[-->+<]>.+[->++<]>.[-->+<]>-...+[->++<]>+...-[-->+<]>-...++[->++<]>.[-->+<]>--.++[->++<]>+...-[-->+<]>--.+++[->++<]>...[-->+<]>---.-[->++++<]>.>++++++++++.>--[-->+++<]>-.[---->+<]>+.[-->+++<]>.[--->++<]>.[-->+++<]>.[--->++<]>...[-->+++<]>+.-[--->++<]>...[-->+++<]>++.--[--->++<]>...++[-->+++<]>.[--->++<]>--.++[-->+++<]>+.-[--->++<]>--.++[-->+++<]>+.-[--->++<]>--.-----[->++<]>-.--[--->++<]>--...-----[->++<]>.[-->+<]>+++++.....----[->++<]>-.+[-->+<]>++++.----[->++<]>.[-->+<]>++++.----[->++<]>.[-->+<]>++++.---[->++<]>-.+[-->+<]>+++.---[->++<]>-.+[-->+<]>+++.[->++<]>+.-[-->+<]>.[->++<]>+.-[-->+<]>.+[->++<]>.[-->+<]>-...+[->++<]>+.-[-->+<]>-.....++[->++<]>.[-->+<]>--.++[->++<]>+.-[-->+<]>--...+++[->++<]>.[-->+<]>---...-[->++++<]>.>++++++++++.>--[-->+++<]>-.[---->+<]>+.[-->+++<]>.[--->++<]>.[-->+++<]>.[--->++<]>...[-->+++<]>+.-[--->++<]>.[-->+++<]>++...--[--->++<]>.++[-->+++<]>...[--->++<]>--.++[-->+++<]>+...-[--->++<]>--.-----[->++<]>-...--[--->++<]>--.-----[->++<]>...[-->+<]>+++++...----[->++<]>-.+[-->+<]>++++.----[->++<]>...[-->+<]>++++.---[->++<]>-...+[-->+<]>+++.[->++<]>+...-[-->+<]>.+[->++<]>...[-->+<]>-.+[->++<]>+.-[-->+<]>-...++[->++<]>...[-->+<]>--.++[->++<]>+...-[-->+<]>--.+++[->++<]>...[-->+<]>---.-[->++++<]>.>++++++++++.>--[-->+++<]>-.[---->+<]>+.[-->+++<]>.[--->++<]>.[-->+++<]>.[--->++<]>...[-->+++<]>+.-[--->++<]>.[-->+++<]>++.--[--->++<]>.....++[-->+++<]>.[--->++<]>--...++[-->+++<]>+.-[--->++<]>--...-----[->++<]>-.--[--->++<]>--.-----[->++<]>.[-->+<]>+++++.-----[->++<]>.[-->+<]>+++++...----[->++<]>-.+[-->+<]>++++.----[->++<]>.[-->+<]>++++.----[->++<]>.[-->+<]>++++...---[->++<]>-.+[-->+<]>+++.[->++<]>+.-[-->+<]>.[->++<]>+.-[-->+<]>.+[->++<]>.[-->+<]>-.+[->++<]>.[-->+<]>-.+[->++<]>+.-[-->+<]>-...++[->++<]>.[-->+<]>--.++[->++<]>.[-->+<]>--.++[->++<]>+.-[-->+<]>--...+++[->++<]>.[-->+<]>---...-[->++++<]>.>++++++++++.>--[-->+++<]>-.[---->+<]>+.[-->+++<]>...[--->++<]>...[-->+++<]>+.-[--->++<]>.[-->+++<]>++...--[--->++<]>.++[-->+++<]>...[--->++<]>--...++[-->+++<]>+.-[--->++<]>--.-----[->++<]>-...--[--->++<]>--.-----[->++<]>...[-->+<]>+++++...----[->++<]>-.+[-->+<]>++++.----[->++<]>...[-->+<]>++++.---[->++<]>-...+[-->+<]>+++.[->++<]>+.-[-->+<]>.[->++<]>+.-[-->+<]>.+[->++<]>...[-->+<]>-.+[->++<]>+...-[-->+<]>-.++[->++<]>...[-->+<]>--.++[->++<]>+...-[-->+<]>--.+++[->++<]>.[-->+<]>---...-[->++++<]>.>++++++++++.>--[-->+++<]>-.[---->+<]>+.................................................................-[->++++<]>.>++++++++++.+[->++++<]>-.++.................................................................--.

\$\endgroup\$
2
\$\begingroup\$

Scala, 267 characters, with bitwise encoding since everything else is worse.

val a="+"+"-"*65+"+"
(a+:(""+:BigInt("sbnatrnet3het8h2l21ala42h2hetrn2trn8trl2g8ha58laha4e5rhesbnatrn8",32).toString(2).grouped(64).map(x=>x.indices.map(i=>if(x(i)=='0')" "else"%X".format((i/4)%16)).mkString).toSeq:+"").map(s=>"|%65s|".format(s)):+a).foreach(println)
\$\endgroup\$
0
\$\begingroup\$

JavaScript 327 characters

It's the best I can do here...

_='console.log("?;%0*K , 77&A:!CCC!/!2!3KK 5!6J7@@ 9 H :!C! < *K4,!&A:BI!DD/ 2J3!4!5 6 6!7@@!H : I!D<0*!,!& :BICC DD>!|;|G?")J #====-$!!!!!!!%|G| 0&7@88 99H*0!1 222 333,4 555 666/>FF % 0!1:A B;G|$$$ < D E!F!%=--->D EEE F?+#####+@ 8G\\nH9 AIB CJ! K 4';for(Y in $='KJIHG@?>=<;:/,*&%$#!')with(_.split($[Y]))_=join(pop());eval(_)

\$\endgroup\$
0
\$\begingroup\$

C (clang), 279 269 273 bytes

Too many printf()s; too many for loops.

(*P)()=printf;f(i,j,k,h){char*t="ckoOc;P5Z5UlolOoB0RXI=??_o7",u[66]={0};P("+%s+\n|%66c\n",memset(u,45,65),'|');for(h=0,i=5;i--;P("|\n"))for(P("| "),j=0;j<16;j++,P(" "),h=h>2?t++,0:h+2)for(k=3;k--;)P("X    XX XXXX"[k+((*t-48>>h)&3)*3]^88?" ":"%X",j);P("|%66c\n+%s+",'|',u);}

Try it online!

\$\endgroup\$
1
-1
\$\begingroup\$

Perl, 486 characters, obviously not even trying hard.

sub p {print @_};p("+",'-'x65,"+\n");p('|',' 'x65,"|\n");
p("| 000   1 222 333 4 4 555 666 777 888 999 AAA B   CCC   D EEE FFF |\n");
p("| 0 0   1   2   3 4 4 5   6     7 8 8 9 9 A A B   C     D E   F   |\n");
p("| 0 0   1 222 333 444 555 666   7 888 999 AAA BBB C   DDD EEE FFF |\n");
p("| 0 0   1 2     3   4   5 6 6   7 8 8   9 A A B B C   D D E   F   |\n");
p("| 000   1 222 333   4 555 666   7 888 999 A A BBB CCC DDD EEE F   |\n");
p('|',' 'x65,"|\n");p("+",'-'x65,"+\n");
\$\endgroup\$

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.