Under construction

Still being built. Things may change

Magical BF 1

Time limit1sMemory limit1024 MB

Summary
Write a BF program that leaves x minus y in cell M0, where M0 and M1 hold x and y with 0 ≤ y ≤ x ≤ 200, and the grid reads correctly by rows and by columns.
Level

Medium6 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

John learned at school that in many East Asian languages texts can be written from left to right as well as from top to bottom. He wondered whether a text can be written so that it reads correctly both ways. In programming class he kept thinking about this too, and now he wants code that solves the tasks when read by rows (top to bottom and left to right) and when read by columns (left to right and top to bottom). For experiments he chose a language called BF.

The memory of a BF program is an infinite array MM with cells numbered from left to right (M0M_0, M1M_1, \ldots). Each cell contains a nonnegative integer that can be arbitrarily large. At the beginning of execution, the data pointer points to the leftmost cell (M0M_0).

Execution starts from the first command. After each command, the program moves on to the next command in the sequence. There are six commands, each denoted by one character:

CommandMeaning
>Moves the data pointer to the right by one cell.
<Moves the data pointer to the left by one cell if the data pointer does not point to the leftmost cell; otherwise does nothing.
+Increases the cell at the data pointer by one.
-Decreases the cell at the data pointer by one if the cell is currently positive; otherwise does nothing.
[If the cell at the data pointer is zero, then jumps forward to the corresponding ] symbol; otherwise does nothing.
]If the cell at the data pointer is nonzero, then jumps back to the corresponding [ symbol; otherwise does nothing.

Help John write magical BF programs for solving the five tasks listed below.

As a solution to each task, submit an N×NN \times N grid of BF program code (where 1≤N≤10001 \le N \le 1000). The code does not have to be the same when read by rows and by columns, but it must solve the task correctly in both cases. The solution text can only contain the characters >, <, +, -, [ and ], and it must completely fill the grid. For any allowed input, the code must not execute more than 1010 million commands.

Task: The cells M0M_0 and M1M_1 of the array contain the integers xx and yy (0≤y≤x≤2000 \le y \le x \le 200), and all other cells contain zeros. Write the difference x−yx-y into the cell M0M_0.

In the output, only the value in cell M0M_0 matters: it must be the difference of xx and yy (in this case, 7−5=27 - 5 = 2). Other cells may contain any numbers (for example, 15001500, 00, 4242, \ldots).

Examples1

  1. Example 1

    Input
    0 0
    
    Expected output
    >><<
    >[-<
    <-<>
    <<>]