LED Numbers and Letters

5

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.

Ming-Tang

Posted 2011-05-23T22:30:04.537

Reputation: 5 383

There is m4 which is turing complete language, so this is still possible, and one char less than cat

– YOU – 2011-05-24T01:31:45.033

3

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.

– dmckee --- ex-moderator kitten – 2011-05-24T01:34:11.147

Didn't notice it is taken on Stack Overflow – Ming-Tang – 2011-05-24T01:42:35.637

5What 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? – mellamokb – 2011-05-24T03:17:35.830

1This 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. – MtnViewMark – 2011-05-28T23:21:40.537

I think [tag:kolmogorov-complexity] problems should be allowed to take auxiliary data for input, with the input length (in bytes) counted against the score. This could reduce overhead in languages that don't handle string literals well, and make it so the program can focus on the data complexity itself. – Joey Adams – 2011-05-29T02:16:20.707

Please answer mellamokb's question, because I want to ask the exact same thing. A bitmap is the most obvious approach.. is that why you discourage it? – Igby Largeman – 2011-05-29T06:06:13.313

because I don't want everyone to post solutions with full of Chinese characters like this. http://codegolf.stackexchange.com/questions/1682/an-old-irish-blessing/1692#1692 I mean, "data encoding" is defined as "creating a hard-coded data, and decoding the data. However, generating the data instead of hard-coding is not 'data encoding' I am talking about".

– Ming-Tang – 2011-05-29T19:04:05.327

1The obvious solution is to count length in bytes after encoding with UTF-8 rather than counting characters. – Peter Taylor – 2011-05-31T19:11:27.553

@Peter I think perhaps the byte/char count isn't what SHiNKiROU turned off by. maybe he just finds Asian characters annoying. Anyway, not allowing encoding to unicode is probably a good idea as it encourages us to find new solutions. – Igby Largeman – 2011-06-01T01:17:52.003

Answers

7

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.

Peter Taylor

Posted 2011-05-23T22:30:04.537

Reputation: 41 901

6

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]

Keith Randall

Posted 2011-05-23T22:30:04.537

Reputation: 19 865

1You can kill 2 chars by replacing X+X+X with X*3. – JPvdMerwe – 2011-05-29T12:28:02.827

2Then 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. – JPvdMerwe – 2011-05-29T12:47:50.167

@JPvdMerwe OMFG, that's an amazing shrink for Python... is there any chance you could apply this same technique in JavaScript loops? – WallyWest – 2014-07-18T01:40:53.717

@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. – JPvdMerwe – 2014-07-18T23:08:17.947

6

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.

Arnaud

Posted 2011-05-23T22:30:04.537

Reputation: 8 231

3

For the sheer fun of it...

BrainFuck 611

Note: Can probably be golfed further.

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

Joshpbarron

Posted 2011-05-23T22:30:04.537

Reputation: 787

2

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)

Rex Kerr

Posted 2011-05-23T22:30:04.537

Reputation: 903

0

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!

gastropner

Posted 2011-05-23T22:30:04.537

Reputation: 3 264

249 bytes – ceilingcat – 2018-12-26T07:11:36.343

0

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(_)

WallyWest

Posted 2011-05-23T22:30:04.537

Reputation: 6 949

-1

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");

piCookie

Posted 2011-05-23T22:30:04.537

Reputation: 99