RoboCritters (etymology) is a brand new esoteric programming language (don't bother searching for it, I just invented it). It's a variant of Brainfuck (BF), slightly more complex than the usual operator substitution schemes. Every program in RoboCritters is a rectangular grid of text that only contains the seven characters . []/\|
, plus newlines to shape the grid.
Example RoboCritters program:
|\/||./|[]||
[..][][] |
|/\|[..][..]
[..] \/\/
To translate a RoboCritters program into BF, look at each non-newline character in the grid in the normal reading order (left-to-right then top-to-bottom), e.g. |\/||./|[]||[..][][] ||/\|[..][..][..] \/\/
.
If the 4×2 section of the grid extending right and down from the current character exactly matches one of the eight robot critters listed below, append the corresponding BF command (><+-.,[]
) to the (initially empty) BF program.
If the 4×2 grid section does not match any of the robot critters or goes out of bounds, nothing is added to the BF program.
Joybot,
>
command:[..] \][/
Calmbot,
<
command:[..] /][\
Squidbot,
+
command:[..] //\\
Spiderbot,
-
command:[..] ||||
Bunnybot,
.
command:[][] [..]
Toothbot,
,
command:[..] |/\|
Foxbot,
[
command:|\/| [..]
Batbot,
]
command:[..] \/\/
So, reading the example program
|\/||./|[]||
[..][][] |
|/\|[..][..]
[..] \/\/
we can see that we first encounter a Foxbot (at column 1, row 1), then a Toothbot (c1,r2), then a Bunnybot (c5,r2), and finally a Batbot (c9,r3). This corresponds to the BF program [,.]
.
Notice that the Foxbot and Toothbot overlap. This is intentional; robot critters are not interpreted any differently when they overlap.
Challenge
Write the shortest program possible that takes in a RoboCritters program and outputs its BF equivalent. You don't need to run the BF or check that it's valid, only translate the RoboCritters code to BF code.
Details
All input RoboCritters programs will be valid, that is they will be an exactly rectangular block of text only containing the seven characters
. []/\|
, plus newlines to shape it. The newlines may be in any convenient common representation. You may optionally assume the programs have a single trailing newline.You must support RoboCritters programs that are smaller than 4×2, including the 0×0 empty (or single newline) program. These all correspond to the empty BF program (the empty string).
The output BF program should be a one-line string only containing the eight BF command characters
><+-.,[]
. There may optionally be a single trailing newline.Take input in any usual way (stdin/text file/command line) and output to stdout or your language's closest alternative.
Instead of a program you may write a function that takes the RoboCritters program as a string and prints or returns the BF program string.
Examples
Input: (variant of example above)
|\/|[][] [..][][] |/\|[..] \/\/
Output:
[,.]
Input: (tests all robot critters)
[..][[[[[..]]. ]|\/| \][/[..]//\\[..][..] [..]/][\[][]|/\|[..] ||||/\| [..]| |\/\/
Output:
>+[<,-.]
Input:
[..] [..] [..] [..] [..] [..] [..] [..] |\/| [..] [..] [..] [..] [..] |\/| [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] [..] |\/| [..] [..] [..] [..] [..] [..] [..] [][] [..] [..] [..] [..] [][] [..] [..] [..] [..] [..] [..] [..] [][] [][] [..] [..] [..] [][] [..] [..] [][] [..] [..] [][] [..] [][] [..] [..] [..] [][] [..] [..] [..] [..] [..] [..] [][] [..] [..] [..] [..] [..] [..] [..] [..] [][] [..] [..] [..] [][] [..] [..] [..] [][] //\\ //\\ //\\ //\\ //\\ //\\ //\\ //\\ [..] \][/ //\\ //\\ //\\ //\\ [..] \][/ //\\ //\\ \][/ //\\ //\\ //\\ \][/ //\\ //\\ //\\ \][/ //\\ /][\ /][\ /][\ /][\ |||| \/\/ \][/ //\\ \][/ //\\ \][/ |||| \][/ \][/ //\\ [..] /][\ \/\/ /][\ |||| \/\/ \][/ \][/ [..] \][/ |||| |||| |||| [..] //\\ //\\ //\\ //\\ //\\ //\\ //\\ [..] [..] //\\ //\\ //\\ [..] \][/ \][/ [..] /][\ |||| [..] /][\ [..] //\\ //\\ //\\ [..] |||| |||| |||| |||| |||| |||| [..] |||| |||| |||| |||| |||| |||| |||| |||| [..] \][/ \][/ //\\ [..] \][/ //\\ //\\ [..]
Output: (BF Hello World program)
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
Input: (no robot critters present)
/\\\[]. ]..[..] \\//||\
Output: (empty string)
Scoring
The shortest submission in bytes wins. (Handy byte counter.) Tiebreaker is highest voted post.