Under construction

Still being built. Things may change

Magical BF 3

Time limit1sMemory limit1024 MB

Summary
Write an N by N grid of BF code that stores the index of the leftmost zero cell in M0, correct when the grid is read by rows and by columns.
Level

Hard8 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

Time limit: 1000 ms. Memory limit: 1024 MB.

John learned at school that many East Asian languages 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, and now he wants to write 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). He chose a language called BF for the experiment.

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

Execution starts from the first command. After each command, the program moves on to the next command in the sequence. The language has 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, jumps forward to the corresponding ] symbol. Otherwise does nothing.
]If the cell at the data pointer is nonzero, jumps back to the corresponding [ symbol. Otherwise does nothing.

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

To solve each task, submit an N×NN \times N grid of BF 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 can only contain the characters >, <, +, -, [, and ], and it must completely fill the grid. For any allowed input, the code must not execute more than 10 million commands.

Task: Find the number of the leftmost cell that contains zero, and write this number into cell M0M_0. By the end of execution, all cells other than M0M_0 may contain any integers. You can assume that the answer does not exceed 100, and that at the start of execution no cell contains a value greater than 50.

Examples1

  1. Example 1

    Input
    0
    
    Expected output
    0