Brainfuck part - kenrube/Esopoly GitHub Wiki

Brainfuck, perhaps, is the most famous representative of the esoteric family, primarily because of its minimalist syntax. Having an asset of only 8 instructions, Brainfuck is Turing-complete, which allows you to write any program on it. But, I can assure you, you will get stuck in the Turing tarpit much faster than write something useful :)

Fortunately, our task is quite simple: print the phrase Brainfuck program. As before, I will not describe the syntax of the language, for this it is enough to look into any article on the language.

The algorithm is extremely simple. In any cell, we form the required value (the ASCII character code, as usual) and print it with the . instruction. In principle, the whole problem can be solved by the sequence + and -, but this is too clumsy and long solution. We will use the capabilities of the language to multiply numbers.

The scheme is simple (assume that we are in cell 0 and all memory is empty):

>            go to cell 1
+...+        assign this value {first multiplier} to this cell (counter)
[            repeat until the value of the current cell is greater than 0
  <          return to cell 0
    +...+    increment value in cell by some value {second multiplier}
  >          go back to the first cell
  -          reduce the counter by 1
]            back to the beginning of the cycle
<            return to cell 0

Or more compact

>+...+[<+...+>-]<

Of course, memory does not have to be empty, and nothing prevents us from being in any other memory cell. If, say, there was some value in the original cell, it would increase with each decrement of the counter by the value of the second multiplier. Similarly, the reduction works.

Following this scheme, we will compose our program for the output of the phrase:

>>++++++[<+++++++++++>-]<.     print 'B' (0 + 6 * 11 = 66)
>++++++[<++++++++>-]<.         print 'r' (66 + 6 * 8 = 114)
>++++[<---->-]<-.              print 'a' (114 - 4 * 4 - 1 = 97)
++++++++.                      print 'i'
+++++.                         print 'n'
--------.                      print 'f'
>+++[<+++++>-]<.               print 'u'
>++++[<---->-]<--.             print 'c'
++++++++.                      print 'k'
>>++++++++[<++++>-]<.          print ' '
[-]<+++++.                     print 'p'
++.                            print 'r'
---.                           print 'o'
--------.                      print 'g'
+++++++++++.                   print 'r'
>++++[<---->-]<-.              print 'a'
++++++++++++.                  print 'm'

After the addition of other languages to the common source code and their reconciliation among themselves, this source began to look slightly different, providing, however, the same output:

><>.-+                         head
>>++++++[<+++++++++++>-]<.     print 'B'
>++++++[<++++++++>-]<.         print 'r'
>++++[<---->-]<-.              print 'a'
++++++++.                      print 'i'
+++++.                         print 'n'
--------.                      print 'f'
>+++[<+++++>-]<.               print 'u'
>++++[<---->-]<--.             print 'c'
++++++++.                      print 'k'
>>++++++++[<++++>-]<.          print ' '
[-]<+++++.                     print 'p'
++.                            print 'r'
---.                           print 'o'
--------.                      print 'g'
+++++++++++.                   print 'r'
>++++[<---->-]<-.              print 'a'
+++++<>+++++++.                print 'm'
<><><>><<><><>><>              tail
<><><<><>><><>><<              --//--
><><><><<<>><>><>              --//--
<>><<><<><>><><><              --//--
><><><><><>><<><<              --//--
>><><>><<><><>><<              --//--
><><<>><><><><><><><           --//--

With head I will henceforth designate that part of the source code in a particular language that is part of the original source code of the program in Malbolge.

tail - instructions that no longer perform useful work, but are present in the resulting source code for the reason that they are needed for some other languages. In this case, for example, they are also used by the EXCON program. Plus Malbolge, of course.

You can look at the process and the result of this program in Brainfuck Visualizer.

Next, we face the task of combining 2 source codes, which we already have.

As you remember, any program in any language in our polyglot should be correct from the point of view of Malbolge. This means that any command from the source in Brainfuck should be located in such a place that when the source code is normalized it becomes a valid instruction from the Malbolge syntax.

This language, by the way, has an interesting feature: its programs can only include printed characters (33-126 in ASCII), so if after calculating the character code for an unnormalized representation the character was outside the gap, the code will automatically be brought back to these borders. For example, 127 is converted to 33, and 32 to 126. And so on. And this means that for each Malbolge command its unnormalized representation is repeated in steps of 94 characters.

It looks like this:

('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)   j
ba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedc   i
'&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)(   *
>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?   p
cba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfed   <
utsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwv   /
QPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSR   v
DCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFE   o

You can make sure by bringing any of these rows into the normalized form in the debugger.

Since our Malbolge program has completed its work with the output of the last character, commands that are outside its source code can be any of j,i,*,p,<,/,v,o. They will not affect the performance of the original program. This allows us to choose the closest location for the next instruction in the Brainfuck source code from all 8 options.

Now we have everything we need to unite. For convenience, we align the source code by 94 characters in width and replace all the missing commands with the nop-instruction.

DCBA@?\nZ;|38x0SA3tsN`Lo98*G"'&%$#Sc>`v<zLxwI5tWrDpoAm?Oj)Laf8dc\aZ~X|?U=Y;v9ONS54JnHG/jJCBGF(
>b%;_"876Z{321U5.-Qr*N('K%$H(hEf${Abaw=^zs9Zp6Wm3kj0Qglk+vooooooooooooo>>o+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+oooooooooooo+ooo[oooooooooooooo<oooooooooooooooo+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+oooooooooooo+oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo++oo
>oooooooooooooooo-oooooo]ooooooooooooo<ooooooooooooo.oo>+ooooooooooooooooo+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+[ooooooooooo<oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+oooooooooooo+oooooooooooooooo>oooooooooooooooo-ooooooooo]ooooooooooo
oooooooo<ooooooo.oo>ooooo+oooooooooooo+oooooooooooooooo++oooooooo[ooooooo<oooooooooooooo--oooo
ooooooooooooooooo-ooooo-oooooooooooo>oooooooooooooooo-ooooooooo]ooooooooo<oooooooooooooo-ooooo
oooooooooooooooo.oo+ooooo+oooooooooooo+oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo++oo
oooooooooooooooo.oo+ooooo+oooooooooooo+oooooooooooooooo++oooooooooooooo.-ooooooooooooooo--oooo
ooooooooooooooooo-ooooo-oooooooooooo-oooooooooooooooo--oooooooooooooooo.>o+ooooooooooooooo++oo
ooooooo[<oooooooooo+ooooo+oooooooooooo+oooooooooooooooo++oooooooooooooo>-ooooooooo]ooooooooooo
oo<ooooooooooooo.oo>ooooo+oooooooooooo+oooooooooooooooo++oooooooo[ooooooo<oooooooooooooo--oooo
ooooooooooooooooo-ooooo-oooooooooooo>oooooooooooooooo-ooooooooo]ooooooooo<oooooooooooooo--oooo
oooooooooooooooo.oo+ooooo+oooooooooooo+oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo++oo
oooooooooooooooo.oo>oooooooooooooooo>o+oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+[ooooooooooo<oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo+ooo
>oooooooooooooooo-oooooo]ooooooooooooo<ooooooooooooo.oooooooooooo[oooooo-ooooooooo]ooooooooooo
oo<oooooooooooooooo+ooooo+oooooooooooo+oooooooooooooooo++oooooooooooooo.oo+ooooooooooooooo+ooo
oooooooooooooooo.-ooooo-oooooooooooo-ooooooooooooooo.--ooooooooooooooooo-ooooooooooooooo--oooo
ooooooooooooooooo-ooooo-oooooooooooo-ooooooooooooooo.oo++ooooooooooooooooo+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+oooooooooooo+oooooooooooooooo++ooooooooooooooooo+oooooooooooo.oooooo
>oooooooooooooooooo+ooooo+oooooooooooo+oooooooooooooooo+ooooooooo[ooooooo<oooooooooooooo--oooo
ooooooooooooooooo-ooooo-oooooooooooo>oooooooooooooooo-ooooooooo]ooooooooo<oooooooooooooo-ooooo
oooooooooooooooo.oo+ooooo+oooooooooooo+oooooooooooooooo++ooooooooooooooooo+ooooooooooooooo++oo
ooooooooooooooooooo+ooooo+oooooooooooo+oooooooooooooooo+ooooooooooooooo.oooooooooooooooooooooo

You can run it in the Brainfuck interpreter and make sure that the two languages work together perfectly well. For Malbolge, however, this source is not yet valid - we will correct this annoying omission later. In the meantime, go further.

⚠️ **GitHub.com Fallback** ⚠️