3
\$\begingroup\$

Given a random code written using Brainfuck commands. You program should translate that code into the following ascii art: each Brainfuck command represents as 5x9 array of A and B symbols. All commands are concatenated with 5x3 arrays of A symbols. Symbols A and B you choose yourself.

For example, when input is ><+,.[] your program might output:

==                 ==       =                                 = = =       = = =  
    ==         ==           =                                 =               =  
       ==   ==          = = = = =                             =               =  
    ==         ==           =           =           =         =               =  
==                 ==       =          =                      = = =       = = =  

Or

@@                 @@       @                                 @ @ @       @ @ @  
    @@         @@           @                                 @               @  
       @@   @@          @ @ @ @ @                             @               @  
    @@         @@           @           @           @         @               @  
@@                 @@       @          @                      @ @ @       @ @ @  

Or even

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

And etc. Trailing spaces and A symbols are allowed.

It is guaranteed that the input will consist only of the symbols > < + , . [ ].

This is a code-golf challenge so the shortest solution wins.

\$\endgroup\$
7
  • \$\begingroup\$ Are ><+,.[] all of the characters that may be in the input? \$\endgroup\$ Feb 21, 2022 at 13:41
  • \$\begingroup\$ @JonathanAllan If the input of the program will include characters that are not included in the list of Brainfuck commands, then the program should not output anything. \$\endgroup\$
    – sinvec
    Feb 21, 2022 at 13:44
  • 6
    \$\begingroup\$ I think guaranteeing input will only consist of valid commands would make the most sense rather than having to add some boiler-plate code to detect or filter out invalid commands - if not, which do we do filter them out or return an empty result if any characters are invalid? Could you add the valid characters too please? \$\endgroup\$ Feb 21, 2022 at 13:56
  • 4
    \$\begingroup\$ Not sure why this is attracting so many down votes with no explanation. Looks like a reasonably specified challenge to me and possibly quite entertaining for anyone who decides to have a go at it. \$\endgroup\$
    – ElPedro
    Feb 22, 2022 at 16:26
  • 1
    \$\begingroup\$ @l4m2 I accidentally forgot to add - when I made this task :) I know it's a little weird, but I think it's too late to change anything. \$\endgroup\$
    – sinvec
    Feb 25, 2022 at 3:05

4 Answers 4

5
\$\begingroup\$

Jelly, 57 bytes

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

A full program accepting a string as the first program argument that prints the result, using 0 for ink and 1 for no ink.

Try it online! (The footer just replaces the 1s with spaces to make it easier to inspect.)

How?

“...’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
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 73 bytes

T>740SúÂX4úD‚„1 9∍ª1D‚7bš9j3δ._Ðí)εû.B}X3úĆS4ú€ûÐ3èÀ4ǝ‚«Ž5¹.IIÇ52%èø3ð×ý»

Uses spaces for \$A\$ and 1 for \$B\$.

It could definitely be golfed by using a different approach, but this will do for now.

Try it online.

Explanation:

Step 1: Create a list of all shapes:

Step 1a: top halve of <:

T>            # Push 11 (10 increments by 1)
  740S        # Push 740 as list: [7,4,0]
      ú       # Pad the "11" with that many leading spaces:
              #  ["       11","    11","11"]

Step 1b: top halve of >:

 Â            # Bifurcate it (short for Duplicate & Reverse copy):
              #  ["11","    11","       11"]

Step 1c: top halve of +:

X             # Push 1
 4ú           # Pad it with 4 leading spaces: "    1"
   D‚         # Pair it with a copy of itself: ["    1","    1"]
     „1       # Push string "1 "
        9∍    # Enlarge it to size 9: "1 1 1 1 1"
          ª   # Append it to the pair:
              #  ["    1","    1","1 1 1 1 1"]

Step 1d: top halve of ]:

 1D‚          # Push pair [1,1]
    7bš       # Prepend "111" (7 as binary string): [111,1,1]
       9j     # Prepend spaces until all are length 9:
              #  ["      111","        1","        1"]
          δ   # Map over each string:
         3 ._ #  Rotate it 3 times towards the left:
              #   ["   111   ","     1   ","     1   "]

Step 1e: top halve of [:

Ð             # Triplicate the list
 í            # Reverse each inner string:
              #  ["   111   ","   1     ","   1     "]

Step 1f: palindromize all of the top halves pushed thus far to get the full shapes:

)             # Wrap the items on the stack into a list
 ε            # Map over each inner list:
  û           #  Palindromize the list to add the bottom halves
   .B         #  Box: add trailing spaces to each line up to the longest line
 }            # Close the map

Step 1g: .:

X             # Push 1
 3ú           # Pad it with 3 leading spaces: "   1"
   Ć          # Enclose; append its own head: "   1 "
    S         # Convert it to a character-list: [" "," "," ","1"," "]
     4ú       # Pad each with 4 spaces:
              #  ["     ","     ","     ","    1","     "]
       €û     # Palindromize each inner string
              #  ["         ","         ","         ","    1    ","         "]

Step 1h: ,:

Ð             # Triplicate the list
 3è           # Pop one and leave its 4th string: "    1    "
   À          # Rotate it once towards the right: "   1   "
    4ǝ        # Replace the 5th string with this:
              #  ["         ","         ","         ","    1    ","   1     "]
‚             # Pair the shapes for `.` and `,` together
 «            # Merge them to the earlier list of shapes

We now have a list of all shapes (with an additional shape for [ due to the triplicate instead of duplicate we've used in step 1e, which will be ignored in (but is necessary for) step 2.

Try just step 1 online.

Step 2: Use the input to get the correct shapes from this list:

Ž5¹           # Push compressed integer 1459
   .I         # Get the (0-based) 1459'th permutation of the list of shapes:
              #  It converts shape-order `<>+]][.,` to `<]>+,].[`
I             # Push the input-string
 Ç            # Convert it to a list of codepoints
              #  "><+,.[]" would become [62,60,43,44,46,91,93]
  52%         # Modulo-52 each: [10,8,43,44,46,39,41]
     è        # 0-based modular index it into the list of shapes
              # (the implicit modular indexing acts as modulo-8: [2,0,3,4,6,7,1])

Try just steps 1 and 2 online.

Step 3: Convert the list of shapes to the correct format and output it as result:

ø             # Zip/transpose the list of shapes; swapping rows/columns
 3ð×          # Push a string of 3 spaces: "   "
    ý         # Join each inner list with this delimiter
     »        # Then join the list of lines by newlines
              # (after which the result is output implicitly)

See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ž5¹ is 1459

\$\endgroup\$
0
\$\begingroup\$

J, 272 236 bytes

l=.|."1 r =.5 9&$@((36$2)&#:)51545900568
p=.5 9&$@((27$2)&#:)4202837
d=.,&(9$0)@}:c=.|.((2 9&$@((15$2)&#:)2050),3 9$0)
m=.|."1 n =.5 9&$@((43$2)&#:)1445260697621
{&' #'@>@(,.&.>/)({&(r;l;p;c;d;n;m;5 3$0)@('><+,.[]_'&i.))"0@((,'_'&,)/) y

-36 bytes by using Catalogue { instead of Agenda @.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 3.8 (pre-release), 257 bytes

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])))

I don't know why it gives me an TypeError, but it works :)

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.