打高尔夫球给我一个ASCII字母


13

您是否发现阅读简单的文字不够吸引人?试试我们的

#####  ###   ###  ##### #####       ##### ##### #   # #####   #
#   # #     #   #   #     #           #   #      # #    #     #
#####  ###  #       #     #           #   ####    #     #     #
#   #     # #   #   #     #           #   #      # #    #      
#   #  ###   ###  ##### #####         #   ##### #   #   #     #

是不是更花哨了?但是,用手写的时间很长,如果有人编写了适合我的程序,那就太好了!

如果您自愿帮助我,那么您的任务是编写一个程序或一个[a-zA-Z\s\n]仅包含一个字符串的函数,然后输出(或返回)它的ascii写作!

您必须使用以下字母来格式化输出:

##### ####   ###  ####  ##### #####  ###  #   # ##### ##### #   # #     #   #
#   # #   # #   # #   # #     #     #     #   #   #     #   #  #  #     ## ##
##### ####  #     #   # ####  ####  #  ## #####   #     #   ###   #     # # #
#   # #   # #   # #   # #     #     #   # #   #   #   # #   # #   #     #   #
#   # ####   ###  ####  ##### #      ###  #   # ##### ###   #  #  ##### #   #

#   #  ###  ####   ###  ####   ###  ##### #   # #   # #   # #   # #   # #####
##  # #   # #   # #   # #   # #       #   #   # #   # #   #  # #   # #     #
# # # #   # ####  #   # ####   ###    #   #   #  # #  # # #   #     #     #
#  ## #   # #     #  ## ##        #   #   #   #  # #  ## ##  # #    #    #
#   #  ###  #      #### # #    ###    #    ###    #   #   # #   #   #   #####

空间:

     |
     | it's a 5x5 square of spaces
     | but had to pad it with |s to make it appear in this post
     |
     |

由于这是一种固定宽度的字体,因此空格字符也被空格包围,从而导致两个字母之间的宽度为7。

a b
     1234567       -- these numbers are just for the example, you don't have to output them
#####       #### 
#   #       #   #
#####       ####
#   #       #   #
#   #       ####

a  b
     1234567890123
#####             #### 
#   #             #   #
#####             ####
#   #             #   #
#   #             ####

当遇到换行符时,如输入

ascii
text

只要确保将两个文本块至少用一个空行分隔即可

#####  ###   ###  ##### ##### 
#   # #     #   #   #     #   
#####  ###  #       #     #    
#   #     # #   #   #     #   
#   #  ###   ###  ##### ##### 

##### ##### #   # #####
  #   #      # #    #  
  #   ####    #     #  
  #   #      # #    #  
  #   ##### #   #   #  

另外,您可以将#s 替换为任何其他字符,只要它在可打印的ASCII范围内且不能为空格。例如,您可以将As用于字母A,将其B用于字母B,依此类推。

因为这是(而且是),所以获胜的提交将是以最小的字节数解决这一挑战的一种方法,玩得开心!


5个字符的空格是否也由单个空格包围,还是可变宽度的字体?
阿达姆,2013年

@Adám,您是对的,应该被空格包围,我将在这一点上进行更新
Katenkyo,2016年

能否以某种方式检索像素字母作为输入,还是必须在额定代码段内构造这些字符?
字节指挥官

@ByteCommander这个挑战的一个(重要)部分是关于字符串压缩,您必须找到在代码中压缩该字母的最佳方法,同时仍然能够检索和使用它:)。是的,它包含在您的高尔夫球代码中,无法输入到您的程序中
Katenkyo,2016年

@Katenkyo Aha,好吧。感谢您的澄清。
字节指挥官

Answers:


6

Python 3,375个字节

f=lambda i:"\n\n".join("\n".join(map(" ".join,zip(*[[x.replace("0"," ")[a*5:a*5+5]for a in range(5)]for x in[["{:025b}".format(int(c,36))for c in'0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH AT6Q9 AT6KK AWU7'.split()][x!=" "and ord(x)-64]for x in j.upper()]])))for j in i.split("\n"))

请参阅在ideone.com上运行的此代码。

相同的代码,但以某种方式很好地缩进,格式化和注释:

f = lambda i: \

    # join multiline strings together using an empty line as separator:
    "\n\n".join(

        # join the string lines of one big output line together: 
        "\n".join(

            # join the corresponding rows of the letters together using " ":
            map(" ".join, zip(*

                # make a list (output line) of list (output characters) 
                # of strings (single character's rows):
                [

                    # replace 0s with spaces and split the bit strings into
                    # chunks of 5 characters - the rows of each letter:
                    [x.replace("0", " ")[a*5 : a*5+5] for a in range(5)]

                    for x in [

                        # split the space separated character codes and
                        # convert them from base 36 to 
                        # base 2 strings of length 25:
                        ["{:025b}".format(int(c, 36)) for c in

                         # the encoded font data (reformatted):
                         '0 JPCFL J2UKE 92Y3Y J2KAM JOMCF JOMC0 92B72 '
                         'AYP81 JFM3J JFMHO AZC7M AB6ZJ B5I5T B43N5 92YWE '
                         'J2UJ4 92YY7 J2UQC 926UM JFM2S AYE5Q AY8G4 AYHKH '
                         'AT6Q9 AT6KK AWU7'.split()]

                        # select element 0 if we want a space, else find
                        # out the index from the ASCII code of the letter:
                        [x != " " and ord(x) - 64] 

                        # repeat for every character in the input line:
                        for x in j.upper()
                    ]
                ]
            ))

        # repeat for every line in the input
        ) for j in i.split("\n")
    )

我还决定采用base 36编码,因为这是Python内置的最高基础int()支持。这是我写的一个简短的Python 3脚本(已解冻),将问题中的字体定义转换为基本的36个代码:我在ideone.com上的转换器

结果由1作为启用像素的字符和作为禁用像素的空格组成。这是一个示例运行:

输入(换行符为\n):

Hello World
Python rocks

输出:

1   1 11111 1     1      111        1   1  111  1111  1     1111 
1   1 1     1     1     1   1       1   1 1   1 1   1 1     1   1
11111 1111  1     1     1   1       1 1 1 1   1 1111  1     1   1
1   1 1     1     1     1   1       11 11 1   1 11    1     1   1
1   1 11111 11111 11111  111        1   1  111  1 1   11111 1111 

1111  1   1 11111 1   1  111  1   1       1111   111   111  1   1  111 
1   1  1 1    1   1   1 1   1 11  1       1   1 1   1 1   1 1  1  1    
1111    1     1   11111 1   1 1 1 1       1111  1   1 1     111    111 
1       1     1   1   1 1   1 1  11       11    1   1 1   1 1 1       1
1       1     1   1   1  111  1   1       1 1    111   111  1  1   111 

4

Clojure,552字节

(defn t[s](print(reduce #(str %1"\n"%2)(map #(apply str %)(let[a[:jpcfl :j2uke :92y3y :j2kam :jomcf :jomc0 :92b72 :ayp81 :jfm3j :jfmho :azc7m :ab6zj :b5i5t :b43n5 :92ywe :j2uj4 :92yy7 :j2uqc :926um :jfm2s :aye5q :ay8g4 :ayhkh :at6q9 :at6kk :je7mn :0]](map(fn[o](map #(str(.replace %"0"" ")"\n")(map(fn[w](reduce #(str %1(.substring %2 w(+ w 5))"0")""(map #(str(apply str(repeat(- 25(count %))"0"))%)(map #(Integer/toString(Integer/valueOf(name %)36)2)(map a(map #(if(= % \space)26(-(int %)97))(.toLowerCase o)))))))(range 0 25 5))))(.split s"\n")))))))

ascii中的每个字母都表示为带有#-1,空格-0的二进制字符串。然后将其转换为基数36,以便仅用5个字符来存储+“:”,以使Clojure知道应将其视为符号。然后,输入用换行符分隔,对于每行,我们将36个基数的字母转换回二进制基数,并获得第一个[0:5]符号,添加换行符号,下一个[5:10]符号,依此类推。

您可以看到它在这里运行-https: //ideone.com/y99ST5


1

SOGL,137 字节(非竞争)

 °f`7-π⅛χ%sΤ↕ņLRΕ⅓9׀b∫rr(¶æKGTΧ3;■ΦΤg¼⁰¡Νg‽}○eΧ²Y∫Οαν⌡l′}¾(8╔ <%╤∙i.d↔ū∫Æo┌jyŗ▲δ⁶=╗$↑yōΛ3h¼╔◄┼)‘’«n.{5{ø}¹,uR{8+:Ahwha’#=?X’«@*}┼L@*┼}pøO

说明:

...‘’«n.{5{ø}¹,uR{8+:Ahwha’#=?X’«@*}┼L@*┼}pøO
...‘                                           push a string with the letter data                            ["..."]
    ’«n                                        split in lengths of 25                                        [[".", ".", ".",...]]
       .{                                      repeat input times                                            [[".", ".", ".",...]]
         5{ø}                                  push 5 empty strings                                          [[".", ".", ".",...], "", "", "", "", ""]
             ¹                                 wrap those in an array                                        [[".", ".", ".",...], ["", "", "", "", ""]]
              ,                                get a string input                                            [[".", ".", ".",...], ["", "", "", "", ""], "Hello World"]
               u                               lowercase it                                                  [[".", ".", ".",...], ["", "", "", "", ""], "hello world"]
                R{                       }     itirate over the ordinals of the string                       [[".", ".", ".",...], ["", "", "", "", ""], 104]
                  8+                           add 8 to the ordinal                                          [[".", ".", ".",...], ["", "", "", "", ""], 112]
                    :A                         save on variable A                                            [[".", ".", ".",...], ["", "", "", "", ""], 112]
                      h                        swap 2 items one below the stack                              [["", "", "", "", ""], [".", ".", ".",...], 112]
                       w                       get the ord+8th item of the letter data array (modulo length) [["", "", "", "", ""], [".", ".", ".",...], "-----  -    -    -  -----"]
                        h                      swap 2 items one below the stack                              [[".", ".", ".",...], ["", "", "", "", ""], "-----  -    -    -  -----"]
                         a                     load the variable A                                           [[".", ".", ".",...], ["", "", "", "", ""], "-----  -    -    -  -----", 112]
                          ’#=?     }           if equals to 40 then                                          [[".", ".", ".",...], ["", "", "", "", ""], "----- -     -     - -----"] (temporalily switching to space case; it incorrectly picks "N" for space) 
                              X                delete the string                                             [[".", ".", ".",...], ["", "", "", "", ""]]
                               ’«@*            push a string with 25 spaces                                  [[".", ".", ".",...], ["", "", "", "", ""], "                         "]
                                    ┼          add the string vertically-then-horizontally to the array      [[".", ".", ".",...], ["", "", "", "", ""], ["-   -", "-   -", "-----", "-   -", "-   -"]] (back to "H")
                                     L@*       push a string with 10 spaces                                  [[".", ".", ".",...], ["", "", "", "", ""], ["-   -", "-   -", "-----", "-   -", "-   -"], "          "]
                                        ┼      add the string vertically-then-horizontally to the array      [[".", ".", ".",...], ["", "", "", "", ""], ["-   -  ", "-   -  ", "-----  ", "-   -  ", "-   -  "]]
                                          p    output the resulted line                                      [[".", ".", ".",...], ["", "", "", "", ""]]
                                           øO  append to output an empty line                                

注意:目前,该语言还不能真正接受多行输入字符串,因此我已经要求它输入数字并读取接下来的x行作为输入。

第一个字符串是

"------ -  - -  - -  ----------- - -- - -- - - - -  --- -   --   --   - - - ------   --   --   - --- ------ - -- - -- - --   ------- -  - -  - -  -     --- -   --   -- - -  -- -----  -    -    -  ------   --   -------   --   --  ---   -------    -    -----  -    --  -  --    -----    -    -    -    ------ -     -   -   ---------- -     -     - ----- --- -   --   --   - --- ------ -  - -  - -   -    --- -   --   --  -- ---------- -- - - -- -   -    -   - - -- - -- - -   - -    -    ------    -    ----     -    -    ----- --     --     -  -- --   -----   -   -     - ------   - - -   -   - - -   --     -     --- -   -    -   --  --- - ---  --   -"

使用使用“”和“-”的自定义词典进行压缩(压缩具有特殊模式,可使用“ \ n-| / _”,因此可以进行更多压缩!)
它按字母顺序每个ascii字符包含25个字符。从上到下依次排序。
字符就像

16b
27c
38d . . .
49e
5af

这就是将它们添加到数组的相同方法。


我一定要检查结果如何!除了需要其他输入之外,您可以与原始规则最接近的方法是要求输入foo\nbar多行输入的形式
Katenkyo

1

Powershell,261253字节

$args-split'
'|%{$s=$_
0..5|%{$l=$_
-join($s|% *per|% t*y|%{$c='_ONO__NQ__QAQQNONON_QQQQQ?QQQQAAAQDDIA[SQQQQADQQQJJ(_OAQOOY_DDGAUUQOQONDQJUDD$QQQQAAQQDEEAQYQAYCPDQJ[JD"QONO_ANQ_GI_QQNA^ENDNDQQD?'[$l*26+$_-65+222*!($_-32)]
0..5|%{' #'[(+$c-shr$_)%2]}})}}

测试脚本:

$f = {

$args-split'
'|%{$s=$_
0..5|%{$l=$_
-join($s|% *per|% t*y|%{$c='_ONO__NQ__QAQQNONON_QQQQQ?QQQQAAAQDDIA[SQQQQADQQQJJ(_OAQOOY_DDGAUUQOQONDQJUDD$QQQQAAQQDEEAQYQAYCPDQJ[JD"QONO_ANQ_GI_QQNA^ENDNDQQD?'[$l*26+$_-65+222*!($_-32)]
0..5|%{' #'[(+$c-shr$_)%2]}})}}

}

&$f "ascii art
text"

输出:

#####  ###   ###  ##### #####       ##### ####  #####
#   # #     #   #   #     #         #   # #   #   #
#####  ###  #       #     #         ##### ####    #
#   #     # #   #   #     #         #   # ##      #
#   #  ###   ###  ##### #####       #   # # #     #

##### ##### #   # #####
  #   #      # #    #
  #   ####    #     #
  #   #      # #    #
  #   ##### #   #   #

注意:

$s|% *per|% t*y 是快捷$s|% toUpper|% toCharArray

关于空间:

对于源字符串的每个字符,脚本从魔术字符串中获取一个符号(位掩码)'_ONO__NQ...'。但是,索引超出了不可思议的字符串空间。在这种情况下,位掩码$c变为空。这意味着所有位均为零。

关于空白行:

该脚本为每个符号显示6行,而不是5行。索引也超出了魔术字符串的空白行。因此,第6行仅包含空格。

最好查看是否打印其他字符而不是空格。例如·

#####··###···###··#####·#####·······#####·####··#####·
#···#·#·····#···#···#·····#·········#···#·#···#···#···
#####··###··#·······#·····#·········#####·####····#···
#···#·····#·#···#···#·····#·········#···#·##······#···
#···#··###···###··#####·#####·······#···#·#·#·····#···
······················································
#####·#####·#···#·#####·
··#···#······#·#····#···
··#···####····#·····#···
··#···#······#·#····#···
··#···#####·#···#···#···
························

0

C(gcc),326字节

第一次刺中它。必须在TIO上包含stdio.h和string.h,但MinGW不需要。

char*p=0,*q;(*X)()=putchar;i,j;f(char*s){for(;p=strtok(p?0:strdup(s),"\n");X(10))for(i=0;i<5;i++,X(10))for(q=p;*q;q++,X(32))for(j=0;j<5;j++)X(((*q==32?0:"OAOAA?A?A?>A1A>?AAA?O1?1OO1?11>1IA>AAOAAO444OO4457A97591111OAKEAAACCIA>AAA>?A?11>AAIN?A?35>1>@>O4444AAAA>AA::4AAEKAA:4:AA:444O842O"[(toupper(*q)-65)*5+i]-48)>>j)&1?35:32);}

在线尝试!


0

的JavaScript(ES6),292个 287 278字节

s=>s.split`
`.map(s=>`vfefvvehvvh1hhefefevhhhhhv
hhhh111h4491rjhhhh14hhhaa8
vf1hffpv4471llhfhfe4hal444
hhhh11hh4551hph1p3g4hara42
hfefv1ehv79vhhe1u5e4e4hh4v`.replace(/.{26}/g,S=>s.replace(/./g,c=>'012345'.replace(/./g,x=>' #'[(P=parseInt)(S[P(c,36)-10]||0,36)>>x&1])))).join`

`

演示版

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.