Code Golf - Banner Generation

2019-01-31 06:47发布

When thanking someone, you don't want to just send them an e-mail saying "Thanks!", you want to have something FLASHY:

Input: THANKS!!
Output:
TTT H H AAA N N K K SSS !!! !!! 
 T  H H A A NNN K K S   !!! !!! 
 T  HHH AAA NNN KK  SSS !!! !!! 
 T  H H A A N N K K   S            
 T  H H A A N N K K SSS !!! !!! 

Write a program to generate a banner. You only have to generate upper-case A-Z along with spaces and exclamation points (what is a banner without an exclamation point?). All characters are made up of a 3x5 grid of the same character (so the S is a 3x5 grid made of S). All output should be on one row (so no newlines). Here are all the letters you need:

Input: ABCDEFGHIJKL
Output:
AAA BBB CCC DD  EEE FFF GGG H H III JJJ K K L
A A B B C   D D E   F   G   H H  I    J K K L
AAA BBB C   D D EE  FF  G G HHH  I    J KK  L
A A B B C   D D E   F   G G H H  I  J J K K L
A A BBB CCC DD  EEE F   GGG H H III JJJ K K LLL

Input: MNOPQRSTUVWX
Output:
M M N N OOO PPP QQQ RR  SSS TTT U U V V W W X X
MMM NNN O O P P Q Q R R S    T  U U V V W W  X
M M NNN O O PPP Q Q RR  SSS  T  U U V V WWW  X
M M N N O O P   QQQ R R   S  T  U U V V WWW  X
M M N N OOO P   QQQ R R SSS  T  UUU  V  WWW X X

Input: YZ!
Output:
Y Y ZZZ !!!
Y Y   Z !!!
YYY  Z  !!!
  Y Z
YYY ZZZ !!!

The winner is the shortest source code, as counted by the number of bytes it takes to store the file in utf-8 encoding. Source code should read input from stdin, output to stdout. You can assume input will only contain [A-Z! ]. If you insult the user on incorrect input, you get a 10 character discount =P.

I was going to require these exact 28 characters, but to make it more interesting, you can choose how you want them to look - whatever makes your code shorter! To prove that your letters do look like normal letters, show the output of the last three runs.


Shortest codes so far, in characters (utf8 encoding if non-ASCII present):

133 J

205 Python

209 Ruby

313 Haskell

345 C89

382 F#

14条回答
成全新的幸福
2楼-- · 2019-01-31 07:49

Python, 250 224 chars

s=raw_input()
for i in range(5):
    for c in s:
        print''.join((' ',c)[int('2zj93fqzj6hsh2bc8i2b1ycncj5yc2v9i0m16dz91gcizj18blbw6wt0p3qqh8svchwc5onna2808of',36)>>((ord(c)-65 if c>'@'else 26)*15+i*3+j)&1]for j in[0,1,2]),
    print

Notes:

  • relies on 2.x print statement considerably;
  • supports spaces.

Running (I changed appearance of a few letters, for aestetic reasons only ;):

$ echo ABCDEFGHIJKL | python code-golf.py
AAA BBB CCC DD  EEE FFF GGG H H III JJJ K K L   
A A B B C   D D E   F   G   H H  I    J K K L   
AAA BBB C   D D EEE FFF G   HHH  I    J KK  L   
A A B B C   D D E   F   G G H H  I  J J K K L   
A A BBB CCC DD  EEE F   GGG H H III JJJ K K LLL 

$ echo MNOPQRSTUVWX | python code-golf.py
M M N N OOO PPP QQQ RR  SSS TTT U U V V W W X X 
MMM NNN O O P P Q Q R R S    T  U U V V W W X X 
M M NNN O O PPP Q Q RR  SSS  T  U U V V WWW  X  
M M N N O O P   QQQ R R   S  T  U U V V WWW X X 
M M N N OOO P   QQQ R R SSS  T  UUU  V  W W X X 

$ echo YZ\! | python code-golf.py
Y Y ZZZ !!! 
Y Y   Z !!! 
YYY  Z  !!! 
  Y Z       
YYY ZZZ !!! 

There are trailing spaces.

查看更多
我只想做你的唯一
3楼-- · 2019-01-31 07:49

Python, 340 characters

d=dict((i,[23535,31727,29263,15211,29391,4815,31567,23533,29847,31527,23277,29257,23421,23549,31599,5103,32623,23275,31183,9367,31597,11117,32749,21653,31213,29351][i-65])for i in range(65,91))
d[33]=29183
d[32]=0
s=raw_input()
for l in range(5):
 p=""
 for c in s:
  for n in range(3):
   if d[ord(c)]&2**(3*l+n):p+=c
   else:p+=" "
  p+=" "
 print p

sample output

>>> 
ABCDEFGHIJKLMNOPQRSTUVWXYZ !
aaa bbb ccc dd  eee fff ggg h h iii jjj k k l   m m n n ooo ppp qqq rr  sss ttt u u v v w w x x y y zzz     !!! 
a a b b c   d d e   f   g   h h  i    j k k l   mmm nnn o o p p q q r r s    t  u u v v w w  x  y y   z     !!! 
aaa bbb c   d d ee  ff  g g hhh  i    j kk  l   m m nnn o o ppp q q rr  sss  t  u u v v www  x  yyy  z      !!! 
a a b b c   d d e   f   g g h h  i  j j k k l   m m n n o o p   qqq r r   s  t  u u v v www  x    y z           
a a bbb ccc dd  eee f   ggg h h iii jjj k k lll m m n n ooo p   qqq r r sss  t  uuu  v  www x x yyy zzz     !!! 
>>> 

not too great, but it was fun writing it

edit whoops, I made the input be lowercase. fixed now, saved me one character too :)

查看更多
登录 后发表回答