Task
Brainfuck is a tiny programming language—also known as an esoteric language—whose programs use only eight different characters. Despite that, Brainfuck is Turing-complete, which means it can do anything the more grown-up programming languages can. A Brainfuck program works with a tape of memory cells, moves along that tape, reads input, and writes output. You can read more on Wikipedia or ask an LLM.
In this task, you are given a mapping from input strings to output strings as a JSON object:
{
"input-1": "output-1",
"input-2": "output-2"
}
Write a Python program that reads this mapping and returns a short Brainfuck program implementing it. For every input string in the mapping, the generated program must print the corresponding output string.
For example, consider this mapping:
{
"A": "B",
"B": "C"
}
A valid generated Brainfuck program is:
,+.
The , command reads the input character into the current cell, + increases
its ASCII value by one, and . prints the result. This turns A into
B and B into C, so the same program works for both inputs.
Correctness
The checker runs your generated Brainfuck program once for every input in the mapping and compares its output with the corresponding expected value. The output must match exactly.
Implementation and checking details
- Only the characters
+-.,<>[]are counted in your answer; everything else is ignored. - The input and output strings contain printable ASCII characters only.
- If the program reads past the end of an input string, 0 is written into the current cell. You can think of every input as ending with an infinite sequence of zero bytes.
- Each tape cell is an unsigned integer from 0 to 255, and all operations are performed modulo 256.
- The tape contains 30 000 cells and wraps around in both directions.
- The program may execute at most one million operations. Try not to get stuck in an infinite loop!
No input strings other than those in the mapping will be tested.
Optimisation
Your goal is to generate a Brainfuck program that is as short as possible. Every test has its own
target length. Meeting that target passes the test and earns 1 point; producing an even shorter
program earns bonus points. If your program is a little longer than the target, you can still earn
partial points: they are awarded when its length is greater than the target but less than
1.1 × target length.
Submission
Submit one Python source file. It is run once for each test. Your program must read the JSON
mapping from stdin and write the generated Brainfuck source code to
stdout.
Limits
Each mapping contains at most 20 input-output pairs. Every input and output string is at most 50 characters long.
The time limit is 10 seconds per test. The memory limit is 512 MiB per test. Your submitted Python source file must not be larger than 256 KiB.
Examples
Most tests are hidden. Here are some inputs you can download and try locally.
