Skip to main content
deleted 1 character in body
Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

Cubix, 10 bytes

(W0^I?>O2@

Test it online!Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

The code is then run with the IP (instruction pointer) starting on the I, facing east. I inputs a signed integer from STDIN, pushing it onto the stack.

The next command is ?, which changes the direction of the IP depending on the sign of the top item. If the input is 0, it keeps moving in same direction, running through the following code:

  • > - Point the IP to the east. (No-op since we're already going east.)
  • O - Output the top item as an integer.
  • 2 - Push 2 to the stack. This is practically a no-op, because...
  • @ - Terminates the program.

If the input is negative, the IP turns left at the ?; because this is a cube, the IP moves onto the 0 in the second row, heading east. 0 pushes a literal 0, then this code is run:

  • ^ - Point the IP north.
  • W - "Sidestep" the IP one spot to the left.
  • ( - Decrement the top item.

The TOS is now -1, and the IP wraps around the cube through a bunch of no-ops . until it hits the >. This runs the same output code mentioned above, outputting -1.

If the input is positive, the same thing happens as with negative inputs, with one exception: the IP turns right instead of left at the ?, and wraps around the cube to the 2, which pushes a literal 2. This is then decremented to 1 and sent to output.

Cubix, 10 bytes

(W0^I?>O2@

Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

The code is then run with the IP (instruction pointer) starting on the I, facing east. I inputs a signed integer from STDIN, pushing it onto the stack.

The next command is ?, which changes the direction of the IP depending on the sign of the top item. If the input is 0, it keeps moving in same direction, running through the following code:

  • > - Point the IP to the east. (No-op since we're already going east.)
  • O - Output the top item as an integer.
  • 2 - Push 2 to the stack. This is practically a no-op, because...
  • @ - Terminates the program.

If the input is negative, the IP turns left at the ?; because this is a cube, the IP moves onto the 0 in the second row, heading east. 0 pushes a literal 0, then this code is run:

  • ^ - Point the IP north.
  • W - "Sidestep" the IP one spot to the left.
  • ( - Decrement the top item.

The TOS is now -1, and the IP wraps around the cube through a bunch of no-ops . until it hits the >. This runs the same output code mentioned above, outputting -1.

If the input is positive, the same thing happens as with negative inputs, with one exception: the IP turns right instead of left at the ?, and wraps around the cube to the 2, which pushes a literal 2. This is then decremented to 1 and sent to output.

Cubix, 10 bytes

(W0^I?>O2@

Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

The code is then run with the IP (instruction pointer) starting on the I, facing east. I inputs a signed integer from STDIN, pushing it onto the stack.

The next command is ?, which changes the direction of the IP depending on the sign of the top item. If the input is 0, it keeps moving in same direction, running through the following code:

  • > - Point the IP to the east. (No-op since we're already going east.)
  • O - Output the top item as an integer.
  • 2 - Push 2 to the stack. This is practically a no-op, because...
  • @ - Terminates the program.

If the input is negative, the IP turns left at the ?; because this is a cube, the IP moves onto the 0 in the second row, heading east. 0 pushes a literal 0, then this code is run:

  • ^ - Point the IP north.
  • W - "Sidestep" the IP one spot to the left.
  • ( - Decrement the top item.

The TOS is now -1, and the IP wraps around the cube through a bunch of no-ops . until it hits the >. This runs the same output code mentioned above, outputting -1.

If the input is positive, the same thing happens as with negative inputs, with one exception: the IP turns right instead of left at the ?, and wraps around the cube to the 2, which pushes a literal 2. This is then decremented to 1 and sent to output.

t
Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

Cubix, 10 bytes

(W0^I?>O2@

Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

How this worksThe code is then run with the IP (instruction pointer) starting on the I, facing east. I inputs a signed integer from STDIN, pushing it onto the stack.

The next command is ?, which changes the direction of the IP depending on the sign of the top item. If the input is 0, it keeps moving in same direction, running through the following code:

  • > - Point the IP to the east. (No-op since we're already going east.)
  • O - Output the top item as an integer.
  • 2 - Push 2 to the stack. This is practically a no-op, because...
  • @ - Terminates the program.

If the input is negative, the IP turns left at the ?; because this is a cube, the IP moves onto the 0 in the second row, heading east. 0 pushes a literal 0, then this code is run:

  • ^ - Point the IP north.
  • W - "Sidestep" the IP one spot to the left.
  • ( - Decrement the top item.

The TOS is now -1, and the IP wraps around the cube through a bunch of no-ops . until it hits the >. This runs the same output code mentioned above, outputting -1.

If the input is positive, the same thing happens as an exercisewith negative inputs, with one exception: the IP turns right instead of left at the ?, and wraps around the cube to the reader. (jk2, I'll add an explanation inwhich pushes a few hoursliteral 2.) This is then decremented to 1 and sent to output.

Cubix, 10 bytes

(W0^I?>O2@

Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

How this works is left as an exercise to the reader. (jk, I'll add an explanation in a few hours.)

Cubix, 10 bytes

(W0^I?>O2@

Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

The code is then run with the IP (instruction pointer) starting on the I, facing east. I inputs a signed integer from STDIN, pushing it onto the stack.

The next command is ?, which changes the direction of the IP depending on the sign of the top item. If the input is 0, it keeps moving in same direction, running through the following code:

  • > - Point the IP to the east. (No-op since we're already going east.)
  • O - Output the top item as an integer.
  • 2 - Push 2 to the stack. This is practically a no-op, because...
  • @ - Terminates the program.

If the input is negative, the IP turns left at the ?; because this is a cube, the IP moves onto the 0 in the second row, heading east. 0 pushes a literal 0, then this code is run:

  • ^ - Point the IP north.
  • W - "Sidestep" the IP one spot to the left.
  • ( - Decrement the top item.

The TOS is now -1, and the IP wraps around the cube through a bunch of no-ops . until it hits the >. This runs the same output code mentioned above, outputting -1.

If the input is positive, the same thing happens as with negative inputs, with one exception: the IP turns right instead of left at the ?, and wraps around the cube to the 2, which pushes a literal 2. This is then decremented to 1 and sent to output.

Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240

Cubix, 10 bytes

(W0^I?>O2@

Test it online!

This code is wrapped to the following cube net:

    ( W
    0 ^
I ? > O 2 @ . .
. . . . . . . .
    . .
    . .

How this works is left as an exercise to the reader. (jk, I'll add an explanation in a few hours.)