2

Possible Duplicate:
Code Golf - Banner Generation

Post your shortest code to convert a number into a ASCII art digits.

Input - Assume that an integer variable called z has already been set containing the number.

Output - Print the output to the console.

Quality - The lower number of characters, the better.

Formatting - Flexible, providing it is ASCII art and looks like a number. There must also be some spacing between digits.

Test input: 365

GGGGGGGGGGG....GGGGGGGGGGGG...GGGGGGGGGGG
..........G....G..............G..........
..........G....G..............G..........
..GGGGGGGGG....GGGGGGGGGGGG...GGGGGGGGGGG
..........G....G..........G.............G
..........G....G..........G.............G
GGGGGGGGGGG....GGGGGGGGGGGG...GGGGGGGGGGG
Community
  • 1
  • 1
Gelatin
  • 2,393
  • 1
  • 24
  • 29
  • 2
    Please read http://meta.stackexchange.com/questions/24242/acceptable-level-of-code-golf-questions. Not a bad code golf, just needs a little more specification. – Chris Lutz Jun 19 '10 at 23:50
  • You should probably also add how each number is represented in this `7x11` matrix. Also things like spacing between each character - should there be 3 spaces between each printed digit? Are those dots only to indicate space, or must be part of the output? – Anurag Jun 20 '10 at 00:01
  • 1
    Very similar to a [recent code-golf](http://stackoverflow.com/questions/2985540/code-golf-banner-generation). –  Jun 20 '10 at 00:07
  • @doublep: Good point, voted to close. – Gelatin Jun 20 '10 at 00:08

3 Answers3

4

Python: 173 characters

for i in range(5):
    a=""
    for j in str(z):
        y=int("03330222220201002020330220102001030022220303003020"[int(j)*5+i])*8
        a+="."+("#"*9+"."*14+"##"+"."*6+"#")[y:y+8]
    print a
Nas Banov
  • 28,347
  • 6
  • 48
  • 67
Gelatin
  • 2,393
  • 1
  • 24
  • 29
  • please note you need to count new lines as well. it's 168 chars with identation but w/o new lines. Need to add +5 for \n = 173 – Nas Banov Jun 20 '10 at 02:42
  • I don't have Python installed on this machine so I'll take your word for it that this works, somehow. There is a voice in the back of my head telling me that you can somehow reduce your character count using a list comprehension, but of course, I may be totally wrong. – Tyler Jun 21 '10 at 05:54
1

Bash: 9 characters

figlet $z

;)

MiffTheFox
  • 21,302
  • 14
  • 69
  • 94
  • 2
    ewwww... this is not solution in bash but in figlet.pls no trivialisms! – Nas Banov Jun 20 '10 at 02:35
  • @EnTrr - When I got here the question was at -1 with a vote to close, I figured it was going to be closed soon and I shouldn't take it so seriously... ;) – MiffTheFox Jun 20 '10 at 03:28
1

Ruby - 139 chars

(0..4).map{|i|puts z.to_s.chars.map{|j|(?#*9+?.*14+'##'+?.*6+?#)[(?0+"ubp9x453o9jzme0cs08".to_i(36).to_s(4))[j.to_i*5+i].to_i*8,8]+' '}*''}

Output for z = 365

> asciinum.rb
######## ######## ########
.......# #....... #.......
######## ######## ########
.......# #......# .......#
######## ######## ########
Dogbert
  • 212,659
  • 41
  • 396
  • 397