代码高尔夫-横幅广告生成 [英] Code Golf - Banner Generation

查看:118
本文介绍了代码高尔夫-横幅广告生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在感谢某人时,您不想只给他们发送一封电子邮件,说:谢谢!",您想要的东西很简单:

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

编写程序以生成横幅.您只需生成大写字母A-Z以及空格和感叹号(什么是没有感叹号的横幅?).所有字符都由相同字符的3x5网格组成(因此S是由S组成的3x5网格).所有输出都应该在一行上(因此不能使用换行符).这是您需要的所有字母:

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

获胜者是最短的源代码,用以 utf-8编码存储文件所需的字节数来计算.源代码应从stdin读取输入,然后输出到stdout.您可以假设输入将仅包含[A-Z! ].如果侮辱用户输入错误,您将获得10个字符的折扣= P.

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.

我原本需要这28个字符,但为了使其更有趣,您可以选择希望它们的外观-可以使代码更短的任何方式!为了证明您的字母看上去确实像普通字母,请显示最后三个运行的输出.

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.

到目前为止,最短的代码,以字符为单位(如果不存在ASCII,则为utf8编码):

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

推荐答案

J,133 135 79 83 84 88 个字符(utf-8编码)

J, 133 135 79 83 84 88 characters (utf-8 encoding)

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

用法:

    ;/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

说明(NB.是J中的注释):

Explanation (NB. is comment in 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.

这篇关于代码高尔夫-横幅广告生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆