Under construction

Still being built. Things may change

Pebbling Odometer 2

Time limit1sMemory limit512 MB

Summary
Write a program that ends on (0, 0) if x is at most y and on (0, 1) otherwise, leaving both pebble counts unchanged.
Level

Hard8 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Operation grid

The odometer moves on an imaginary square grid of 256×256256 \times 256 unit cells. Each cell can contain at most 15 pebbles and is identified by a pair of coordinates (row, column), where each coordinate is in the range 0, ..., 255. Given a cell (i,j)(i, j), the adjacent cells are (if they exist) (i−1,j)(i - 1, j), (i+1,j)(i + 1, j), (i,j−1)(i, j - 1) and (i,j+1)(i, j + 1). Any cell on the first or last row, or on the first or last column, is called a border. The odometer always starts at cell (0,0)(0, 0) (the north-west corner), facing north.

Basic commands

The odometer runs the commands in the order they appear in the program. A program has at most one command per line. Empty lines are ignored. The symbol # starts a comment, and any text after it up to the end of the line is ignored. If the odometer reaches the end of the program, execution stops.

  • left: turn 90 degrees to the left (counter clockwise) and stay in the current cell.
  • right: turn 90 degrees to the right (clockwise) and stay in the current cell.
  • move: move one unit forward into the adjacent cell. If the border in that direction has already been reached, this command has no effect.
  • get: remove one pebble from the current cell. If the cell has no pebbles, this command has no effect.
  • put: add one pebble to the current cell. If the cell already has 15 pebbles, this command has no effect. The odometer never runs out of pebbles.
  • halt: terminate the execution.

Labels, borders and pebbles

Labels are case-sensitive strings of at most 128 symbols chosen from a to z, A to Z, and 0 to 9. In the descriptions below, L stands for any valid label.

  • L: declares the location of label L in the program. All declared labels must be unique. A declaration has no effect on the odometer.
  • jump L jumps unconditionally to the line with label L.
  • border L jumps to label L if the odometer is on a border and faces the edge of the grid, so that a move would have no effect. Otherwise, execution continues normally.
  • pebble L jumps to label L if the current cell contains at least one pebble. Otherwise, execution continues normally.

Program size and execution length

The size of a program is the number of commands in it. Label declarations, comments and blank lines are not counted. The execution length is the number of steps performed. Every command execution counts as one step, whether or not the command had an effect. Label declarations, comments and blank lines do not count as steps.

Task

At the start, cell (0,0)(0, 0) holds xx pebbles and cell (0,1)(0, 1) holds yy pebbles. All other cells are empty. Write a program that terminates with the odometer in cell (0,0)(0, 0) if x≤yx \le y, and in cell (0,1)(0, 1) otherwise. At the end, cell (0,0)(0, 0) must contain exactly xx pebbles and cell (0,1)(0, 1) must contain exactly yy pebbles. Remember that no cell can hold more than 15 pebbles.

Limits

The program size must be at most 200. The execution length must be at most 2000.

Examples1

  1. Example 1

    Input
    0 0
    
    Expected output
    right
    L:
    pebble A
    jump D1
    A:
    move
    pebble B
    jump D2
    B:
    get
    right
    move
    put
    right
    right
    move
    left
    move
    get
    left
    move
    put
    right
    right
    move
    right
    jump L
    D1:
    right
    move
    P1:
    pebble P1a
    jump P1d
    P1a:
    get
    right
    right
    move
    put
    right
    right
    move
    jump P1
    P1d:
    left
    move
    Q1:
    pebble Q1a
    jump Q1d
    Q1a:
    get
    left
    move
    put
    right
    right
    move
    left
    jump Q1
    Q1d:
    left
    move
    left
    move
    halt
    D2:
    left
    left
    move
    left
    move
    P2:
    pebble P2a
    jump P2d
    P2a:
    get
    right
    right
    move
    put
    right
    right
    move
    jump P2
    P2d:
    left
    move
    Q2:
    pebble Q2a
    jump Q2d
    Q2a:
    get
    left
    move
    put
    right
    right
    move
    left
    jump Q2
    Q2d:
    left
    move
    halt