首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASCII Brainfuck

ASCII Brainfuck
EN

Code Golf用户
提问于 2022-02-21 13:37:17
回答 2查看 484关注 0票数 3

给出了使用Brainfuck命令编写的随机代码。您的程序应该将该代码转换为以下ascii技巧:每个Brainfuck命令表示为5x9数组的AB符号。所有命令都与5x3数组的A符号连接。符号AB你选择自己。

例如,当输入为><+,.[]时,程序可能会输出:

代码语言:javascript
复制
==                 ==       =                                 = = =       = = =  
    ==         ==           =                                 =               =  
       ==   ==          = = = = =                             =               =  
    ==         ==           =           =           =         =               =  
==                 ==       =          =                      = = =       = = =  

代码语言:javascript
复制
@@                 @@       @                                 @ @ @       @ @ @  
    @@         @@           @                                 @               @  
       @@   @@          @ @ @ @ @                             @               @  
    @@         @@           @           @           @         @               @  
@@                 @@       @          @                      @ @ @       @ @ @  

甚至

代码语言:javascript
复制
..ooooooooooooooooo..ooooooo.ooooooooooooooooooooooooooooooooo.o.o.ooooooo.o.o.oo
oooo..ooooooooo..ooooooooooo.ooooooooooooooooooooooooooooooooo.ooooooooooooooo.oo
ooooooo..ooo..oooooooooo.o.o.o.o.ooooooooooooooooooooooooooooo.ooooooooooooooo.oo
oooo..ooooooooo..ooooooooooo.ooooooooooo.ooooooooooo.ooooooooo.ooooooooooooooo.oo
..ooooooooooooooooo..ooooooo.oooooooooo.oooooooooooooooooooooo.o.o.ooooooo.o.o.oo

等等,尾随空格和A符号是允许的。

保证输入仅由符号> < + , . [ ]组成。

这是一个代码-高尔夫挑战,所以最短的解决方案获胜。

EN

回答 2

Code Golf用户

发布于 2022-02-21 18:48:37

果冻,57 字节数

代码语言:javascript
复制
“ṾÆxÑ3øḤC⁵ịJYSLẇɱ⁼’Bs3ŒBJṫ⁴Ɗ¦z1m€0Ṛs€9
⁽HṠ,17ḥⱮịⱮ¢j€⁶ẋ3¤Y

接受字符串作为输出结果的第一个程序参数的完整程序,使用0表示墨迹,而1不使用墨水。

在网上试试! (页脚将1s替换为空格,以便于检查)。

怎么做?

代码语言:javascript
复制
“...’Bs3ŒBJṫ⁴Ɗ¦z1m€0Ṛs€9 - Link 1: no arguments
“...’                    - 43552819895870853685529620449548093603391
     B                   - in binary
      s3                 - split into chunks of length 3
                           -> columns of the bottom half of 5 of the 7 characters
                              the '[' and '>' are created using reflection later
                              the comma is reversed too, we'll use its reflection
              ¦          - sparse application...
             Ɗ           - ...to indices: last three links as a monad:
          J              -   range of length
            ⁴            -   16
           ṫ             -   tail (covers the columns containing ',' and '.')
        ŒB               - ...apply: bounce ("something" -> "somethingnihtemos")
               z1        - transpose with filler 1 (fills where we didn't reflect)
                 m€0     - reflect each (constructing our ']', '>', and ',')
                    Ṛ    - reverse
                           -> a list of the lines of a representation (without
                              any spacing) of ",.+<][>+.," where the first
                              comma is reversed.
                     s€9 - split each line into chunks of length 9

⁽HṠ,17ḥⱮịⱮ¢j€⁶ẋ3¤Y - Main Link: list of characters, C
⁽HṠ,17             - [19206,17]
       Ɱ           - map across C with:
      ḥ            -   hash with salt 19206 and domain [1,2,...,17]
                       -> maps: ".[,+<]>" to 2,6,10,13,14,15,17
          ¢        - call Link 1 as a nilad
         Ɱ         - map across the lines of the result with:
        ị          -   index into
                       -> 1-indexed and modular, so e.g. 17 gets the 7th item,
                          the part of the line for a '>'.
                ¤  - nilad followed by links as a nilad:
             ⁶     -   space character
              ẋ3   -   repeated three times
           j€      - join each list of line parts with three spaces
                 Y - join with newline characters
                   - implicit, smashing print
票数 5
EN

Code Golf用户

发布于 2022-03-08 12:50:35

Python3.8 (预发行版),257个字节

代码语言:javascript
复制
lambda s:'\n'.join(list(map(lambda i:print("111".join([list(map(lambda s:str(s)[3:],map(bin,[0x9FFF9EFFFFFF57AB,0xF9F9FEFFFFFF7FFB,0xFF0FEAAFFFFF7FFB,0xF9F9FEFF7FBF7FFB,0x9FFF9EFEFFFF57AB])))[i][(p:="><+,.[]".index(c))*9:(p+1)*9]for c in s])),[0,1,2,3,4])))

我不知道为什么它给我一个TypeError,但它有效:)

在网上试试!

票数 0
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/243164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档