Question

« Merci! »

Quand quelqu'un remercier, vous ne voulez pas simplement leur envoyer un e-mail disant que vous voulez avoir quelque chose 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 !!! !!! 

Ecrire un programme pour générer une bannière. Il vous suffit de générer des majuscules A-Z ainsi que des espaces et des points d'exclamation (ce qui est une bannière sans point d'exclamation?). Tous les caractères sont constitués d'une grille de 3x5 de même nature (de sorte que le S est une grille de 3x5 en S). Toutes les sorties doivent être sur une ligne (donc pas de retour à la ligne). Voici toutes les lettres dont vous avez besoin:

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 !!!

Le gagnant est le code source la plus courte , comme compté par le nombre d'octets qu'il faut pour stocker le fichier dans encodage UTF-8 . Le code source doit l'entrée STDIN, sortie à stdout. Vous pouvez supposer entrée ne contiendra [A-Z! ]. Si vous insultez l'utilisateur sur l'entrée incorrecte, vous obtenez un 10 caractère de réduction = P.

Je requerrait ces 28 caractères exacts, mais pour le rendre plus intéressant, vous pouvez choisir la façon dont vous les voulez regarder - ce qui rend votre code plus court! Pour prouver que vos lettres ne ressemblent à des lettres normales, montrent la sortie des trois dernières courses.


codes plus courts jusqu'à présent, en caractères (UTF8 codage le cas échéant non-ASCII):

133 J

205 Python

209 Ruby

313 Haskell

345 C89

382 F #

Était-ce utile?

La solution

J, 133 135 79 83 84 88 caractères (UTF 8 codage)

;/5 3$"1(' ',.s){~"1#:3 u:(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧'){~0>.64-~a.i.s=:

Utilisation:

    ;/5 3$"1(' ',.s){~"1#:3 u:(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧'){~0>.64-~a.i.s=:'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│   │!!!│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘

    ;/5 3$"1(' ',.s){~"1#:3 u:(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧'){~0>.64-~a.i.s=:'this is incorrect input.'
|index error

Explication (NB. est un commentaire dans J):

;/              NB. String together along the third dimension...
5 3$"1          NB. ... reshape each line to 5x3...
(' ',.s)        NB. ... a space before each letter of the input string...
{~"1            NB. ... indexed using...
#:              NB. ... the (15 bit) binary representation of ...
3 u:            NB. ... the integer representation of...
(ucp'翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧')  ... the unicode versions of these code points...
{~              NB. ...indexed using...
0>.             NB. ...the max of 0 and...
64-~            NB. ...64 less than...
a.i.            NB. the ascii indexes of s
s=:             NB. Assign the input string to the variable s.

Autres conseils

Python, 250 224 caractères

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:

  • repose sur 2.x considérablement déclaration d'impression;
  • supports espaces.

L'exécution (j'ai changé l'apparence de quelques lettres, pour des raisons d'esthétique seulement;):

$ 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 !!! 

Il y a des espaces de fin.

Figlet (0 caractères)

wget -q 3.ly/gzkv;figlet -f b

Exemple de sortie:

% wget -q 3.ly/gzkv;figlet -f b ABCDEFGHIJKLMNOPQRS

 A  BB   CC DD  EEE FFF  GG H H III  JJ K K L   M M NNN  O  PP   Q  RR   SS 
A A B B C   D D E   F   G   H H  I    J K K L   MMM N N O O P P Q Q R R S   
AAA BB  C   D D EE  FF  G G HHH  I    J KK  L   MMM N N O O PP  Q Q RR   S  
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    QQ R R   S 
A A BB   CC DD  EEE F    GG H H III  J  K K LLL M M N N  O  P     Q R R SS 
% wget -q 3.ly/gzkv;figlet -f b TUVWXYZ \!

TTT U U V V W W X X Y Y ZZZ     !!! 
 T  U U V V W W X X Y Y   Z     !!! 
 T  U U V V WWW  X   Y   Z      !!! 
 T  U U V V WWW X X  Y  Z           
 T  UUU  V  W W X X  Y  ZZZ     !!! 

Python, 233 231 225 224 205 caractères

Candidat pour la plus courte solution python ici :-)
Il est de deux lignes - la dernière ligne a été cassée en 3 pour urrrr lisibilité

s=raw_input()
for i in range(5):print' '.join(''.join((' ',c)[ord(
'W_E__U__QQ_QN_UQ_EA_Q]_D_Q_QYQ__D[_PP_B__F__Q__EG_Y__EZWU]A_A_P_OPO_\\_QNQWT_YUS'
[max(0,3*ord(c)-192-k)])>>i&1]for k in(2,1,0))for c in s)

ps. Merci pour les commentaires, les problèmes corrigés et en utilisant maintenant seulement ASCII 7 bits!

bannière test:

TTT H H EEE     QQQ U U III CCC K K     BBB RR  OOO W W N N     FFF OOO X X     JJJ U U M M PPP SSS     OOO V V EEE RR      TTT H H EEE     L   AAA ZZZ Y Y     DD  OOO GGG !!!
 T  H H E       Q Q U U  I  C   K K     B B R R O O W W NNN     F   O O  X        J U U MMM P P S       O O V V E   R R      T  H H E       L   A A   Z Y Y     D D O O G   !!!
 T  HHH EE      Q Q U U  I  C   KK      BBB RR  O O WWW NNN     FF  O O  X        J U U M M PPP SSS     O O V V EE  RR       T  HHH EE      L   AAA  Z  YYY     D D O O G G !!!
 T  H H E       QQQ U U  I  C   K K     B B R R O O WWW N N     F   O O  X      J J U U M M P     S     O O V V E   R R      T  H H E       L   A A Z     Y     D D O O G G    
 T  H H EEE     QQQ UUU III CCC K K     BBB R R OOO WWW N N     F   OOO X X     JJJ UUU M M P   SSS     OOO  V  EEE R R      T  H H EEE     LLL A A ZZZ YYY     DD  OOO GGG !!!

Haskell, 313 316 320

import Data.Bits
import Data.Char
c&True=c
c&_=' '
a ' '='@'
a '!'='['
a c=c
q s=unlines[s>>= \c->take 3(drop(84*n+3*(ord(a c)-64))$map((c&).testBit(0xffdebaf79f6fbfde7bfe8062f6a979b69b55a4d368ebaf6aeefbe9717add3f8f2ab6a36dbf9b1524d368fedb6fefff69bfdffbff8::Integer))[0..])++" "|n<-[0..4]]
main=getLine>>=putStr.q

Pour les curieux, le grand nombre est la version hexagonale de encoding dans le code suivant. Le numéro est simplement utilisé comme un bitmap. Je n'ai pas eu de succès avec le code shortening plus en codant le nombre d'autres bases même avec des représentations de caractères non standard.

formats :: [String] -- order: [ A-Z!] <- that's a space in front of A
formats = [
    "   AAABBBCCCDD EEEFFFGGGH HIIIJJJK KL  M MN NOOOPPPQQQRR SSSTTTU UV VW WX XY YZZZ!!!"
  , "   A AB BC  D DE  F  G  H H I   JK KL  MMMNNNO OP PQ QR RS   T U UV VW W X Y Y  Z!!!"
  , "   AAABBBC  D DEE FF G GHHH I   JKK L  M MNNNO OPPPQ QRR SSS T U UV VWWW X YYY Z !!!"
  , "   A AB BC  D DE  F  G GH H I J JK KL  M MN NO OP  QQQR R  S T U UV VWWW X   YZ     "
  , "   A ABBBCCCDD EEEF  GGGH HIIIJJJK KLLLM MN NOOOP  QQQR RSSS T UUU V WWWX XYYYZZZ!!!"
  ]

charToBool :: Char -> Bool
charToBool ' ' = False
charToBool _   = True

boolToInteger :: Bool -> Integer
boolToInteger True = 1
boolToInteger _    = 0

encoding :: Integer
encoding = foldr f 0 $ zip [0..] $ map charToBool $ concat formats
  where
    f (pow, bool) z = z + ((2^pow) * boolToInteger bool)

Python 2.6, 251 - 243 - 227 caractères

J'ai essayé une approche légèrement différente (bitpacking parties les lettres sont faites de) ...

  • poignées en majuscules lettres, espaces, point d'exclamation.
  • 2 linebreaks inutiles ajouté ici pour une meilleure lisibilité (la boucle pourrait être une ligne)
  • assurez-vous de l'enregistrer comme UTF-8 avec BOM!

Comme toujours, tous vos commentaires et suggestions! Contender pour la plus courte solution Python (encore quelques caractères derrière pour le moment) ...

w=raw_input()
for l in range(5):print''.join("1111 11  11  1   1   "
[int(("%05d"%ord(u"<ϳϲࢬ禉ऐऒ࠾⬃ᅘᖆⰯ囌❿✛іϾь穏ࠂᅜ⭦⭪⫸㡩⬪㰼"
[max(0,ord(c)-64)]))[l])*3:][:3].replace("1",c)+" "for c in w)

C89, 345 caractères

Les nouvelles lignes ajoutée pour votre santé mentale (ils ne sont pas inclus dans le nombre de caractères et peuvent / doivent être supprimés):

char o[5][99];
d[]={0x2df7fbef,0x3927bb6b,0x396792cf,0x3da7dbed,0x3a4bfb27,0x2d76f249,0x2dbedbfd,0x3db793ef,0x3fb7daeb,0x3ce7a497,0x3db6ab6d,0x3ff6d495,0x3cf6f2a7,0x38ff8000};
c,i,j;
main(){memset(o,32,495);
while((c=getchar())>0){
for(j=0;j<15;j++)
o[j/3][i+j%3]=d[c-33?(c-65)/2:13]>>((c&1)*15+j)&1?c:32;i+=4;}
for(j=0;j<5;j++)printf("%.*s\n",i,o[j]);}

Ruby : 207 215 252 345 caractères

i=gets.chomp;5.times{|t|p i.gsub(/./){|c|j=3*(c>?@?c.ord-64:0);(3*t..3*t+2).map{|d|"mini5mbmzjf2bqjmof3prl72i5pn138iuhylmkpi65i278kq3qjfaihyjb66787odp8ktiy5hwt78tmnb"[j..j+2].to_i(36)[d]==1?c:" "}.join+" "}}

F #, 382 caractères

I compressé deux lettres de chaque rangée dans un octet ASCII imprimable, et la manipulation d'espace et un point d'exclamation spécialement.

let s,(!)=stdin.ReadLine(),printf"%s"
for n in 0..4 do
 for c in s do if c=' '||n=3&&c='!'then !"    "elif c='!'then !"!!! "else for x in 0..3 do printf"%c"(if(Array.collect(fun b->let B n=int b&&&n=0 in[|(B 64)||not(B 8);B 32;B 16;true;B 4;B 2;B 1;true|])"wvwuwTUwvwUUWUEDEiTwUUBURQwEfWidWWVrUrrUEDUmTUTuZUr\\WvtuwWUturruw"B).[n*104+(int c-int 'A')*4+x]then ' 'else c)
 !"\n"

I / O Exemple ci-dessous:

HELLO WORLD!!!
H H EEE L   L   OOO     W W OOO RR  L   DD  !!! !!! !!!
H H E   L   L   O O     W W O O R R L   D D !!! !!! !!!
HHH EE  L   L   O O     WWW O O RR  L   D D !!! !!! !!!
H H E   L   L   O O     WWW O O R R L   D D
H H EEE LLL LLL OOO     WWW OOO R R LLL DD  !!! !!! !!!

ABCDEFGHIJKL
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

MNOPQRSTUVWXYZ
M M N N OOO PPP QQQ RR  SSS TTT U U V V W W X X Y Y ZZZ
MMM NNN O O P P Q Q R R S    T  U U V V W W  X  Y Y   Z
M M NNN O O PPP Q Q RR  SSS  T  U U V V WWW  X  YYY  Z
M M N N O O P   QQQ R R   S  T  U U V V WWW  X    Y Z
M M N N OOO P   QQQ R R SSS  T  UUU  V  WWW X X YYY ZZZ

Python, 340 caractères

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

sortie échantillon

>>> 
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     !!! 
>>> 

pas trop grand, mais il était amusant d'écrire ce

modifier oups, j'ai fait l'entrée soit en minuscule. fixe maintenant, m'a sauvé un caractère trop:)

Delphi, 397 caractères

Ok, avec tous les BEGIN / fin Delphi ne sera probablement jamais plus courte que toute autre langue, mais je ne vois un défi à l'obtenir le plus court possible.

vvar s:String;i,j,k:Word;const F:Array[65..92]of Word=($5BEA,$3AEB,$624E,$3B6B,$72CF,$12CF,$6B4E,$5BED,$7497,$2B26,$5AED,$7249,$5BFD,$5B6F,$2B6A,$12EB,$4D6A,$5AEB,$388E,$2497,$7B6D,$2B6D,$5FED,$5AAD,$24AD,$72A7,$2092,$0000);begin S:=ParamStr(1);for j:=0 to 4 do begin for k:=1 to Length(S)do begin for i := 0 to 2 do Write((' '+S[k])[1+(F[ord(S[k])]shr(i+j*3))and 1]);Write(' ');end;WriteLn;end;end.

La police est construit comme ceci:

010 110 011 110 111 111 011 101 111 011 101 100 101 111 010 110 010 110 011 111 101 101 101 101 101 111 010 000
101 101 100 101 100 100 100 101 010 001 101 100 111 101 101 101 101 101 100 010 101 101 101 101 101 001 010 000
111 110 100 101 110 110 101 111 010 001 110 100 111 101 101 110 101 110 010 010 101 101 111 010 010 010 010 000
101 101 100 101 100 100 101 101 010 101 101 100 101 101 101 100 011 101 001 010 101 101 111 101 010 100 000 000
101 110 011 110 111 100 011 101 111 010 101 111 101 101 010 100 001 101 110 010 111 010 101 101 010 111 010 000

Les caractères dans ce 5x3 de la police prendre jusqu'à 15 bits et sont mémorisés dans le mot (UINT16) dans cet ordre:

00 01 02
03 04 05
06 07 08
09 10 11
12 13 14

Code Formaté:

var
  s:String;    
  i, j, k: Word;

const
  F: Array [65 .. 92] of Word = (
    $5BEA,$3AEB,$624E,$3B6B,    $72CF,$12CF,$6B4E,$5BED,
    $7497,$2B26,$5AED,$7249,    $5BFD,$5B6F,$2B6A,$12EB,
    $4D6A,$5AEB,$388E,$2497,    $7B6D,$2B6D,$5FED,$5AAD,
    $24AD,$72A7,$2092,$0000);

begin
  S := ParamStr(1);
  for j := 0 to 4 do
  begin
    for k := 1 to Length(S) do
    begin
      for i := 0 to 2 do
        Write((' '+S[k])[1+(F[ord(S[k])]shr(i+j*3))and 1]);
      Write(' ');
    end;
    WriteLn;
  end;
end.

Python: 259 caractères

Pas le plus court, mais étant donné que c'était mon premier script Python, je suis plus que satisfait.

k=raw_input()
for i in range(5):print' '.join(''.join((' ',x)[int(z)]for z in bin(int(''.join('%02d'%(ord(q)-43)for q in'xwxvxabxwxbbdqbXWX@axbbUb_^qxXwd@kddcsbssqbXWvDabav7bs9+dwuvxdbuvssvxq')[i*28+'ABCDEFGHIJKLMNOPQRSTUVWXYZ! '.find(x)],8))[2:])for x in k)

Perl, 69 74 77 78 79 caractères

$a=<>;s:(?{$z=substr$a,$-[0]/4,1})z|#:$z:g,print for`figlet -f3x5 $a`

Exemple de sortie:

% echo ABCDEFGHIJKLMNOPQRS | perl banner.pl

 A  BB   CC DD  EEE FFF  GG H H III  JJ K K L   M M NNN  O  PP   Q  RR   SS 
A A B B C   D D E   F   G   H H  I    J K K L   MMM N N O O P P Q Q R R S   
AAA BB  C   D D EE  FF  G G HHH  I    J KK  L   MMM N N O O PP  Q Q RR   S  
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    QQ R R   S 
A A BB   CC DD  EEE F    GG H H III  J  K K LLL M M N N  O  P     Q R R SS  
% echo TUVWXYZ \! | perl banner.pl 

TTT U U V V W W X X Y Y ZZZ      !  
 T  U U V V W W X X Y Y   Z      !  
 T  U U V V WWW  X   Y   Z       !  
 T  U U V V WWW X X  Y  Z           
 T  UUU  V  W W X X  Y  ZZZ      !  

Je suppose que vous avez figlet et cette figlet police installé sur votre système. :)

C #, 239 231 229 caractères (292 octets)

Je suis un peu en retard mais cela ressemblait à du plaisir.

using C=System.Console;class P{static void Main(){var t=C.ReadLine();for(int
b=15,s;b>0;b-=3){foreach(var c in t)for(s=0;s++<4;)C.Write(s>3||c<33?' ':((
"翇篭篯礧歮禧禤祯寭璗牯宭䤧彭忭筯篤筿殭秏璒孯孪寿咕寏犧"[c<34?0:c-64])&1<<b-s)>0
?c:' ');C.WriteLine();}}}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top