Under construction

Still being built. Things may change

Magical BF 2

Time limit1sMemory limit1024 MB

Summary
Write an N by N BF grid that leaves x mod 7 in cell M0 for input x up to 200, whether the grid is read by rows or by columns.
Level

Hard8 of 10

Topics
Implementation, Math
Solved
No attempts yet

Problem

At school, John learned that many East Asian languages can be written from left to right or from top to bottom. He especially wanted to know whether a text can be written so that it reads correctly both ways. In programming class that question kept coming back, so now he wants code that solves the tasks when read by rows (top to bottom, left to right) and when read by columns (left to right, top to bottom). He picked BF as the language for his experiments.

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 holds a nonnegative integer that can grow arbitrarily large. At the start, the data pointer points to the leftmost cell M0M_0.

Execution starts at the first command. After most commands, 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.

Submit each solution as 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: The cell M0M_0 contains an integer xx (0≤x≤2000 \le x \le 200), and all other cells contain zeros. Write the remainder of dividing xx by 77 into the cell M0M_0. When execution ends, cells other than M0M_0 may contain any numbers.

Examples1

  1. Example 1

    Input
    0
    
    Expected output
    0