33 is a simple esolang I created. You may have seen me use it in a few questions. You're not going to be writing a full interpreter. The interpreter you will be writing is for a simplified version of 33.
This simplified 33 has two numeric registers: the accumulator and the counter. The accumulator holds all the post-arithmetic values, the counter is where numbers in the program come from. Both registers are initialized to 0.
0-9 | Appends the digit to the counter
a | Adds the counter to the accumulator
m | Subtracts the counter from the accumulator
x | Multiplies the accumulator by the counter
d | Divides the accumulator by the counter
r | Divides the accumulator by the counter, but stores the remainder in the accumulator
z | Sets the counter to 0
c | Swaps the accumulator and counter
-----
p | Outputs the current value of the accumulator as an ASCII character
o | Outputs the current value of the accumulator as a formatted decimal number
i | Outputs a newline character (0x0a)
-----
P | Stores the ASCII value of the next character read in the accumulator
O | Stores the next integer read into the accumulator
-----
n | Skips the next instruction if the accumulator is not 0
N | Skips the next instruction if the accumulator is 0
g | Skips the next instruction if the accumulator is less than or equal to 0
G | Skips the next instruction if the accumulator is greater than 0
h | Skips the next instruction if the accumulator is greater than or equal to 0
H | Skips the next instruction if the accumulator is less than 0
Test cases
Program / Input -> Output
2o -> 0
25co -> 25
1a0aoi -> 11 (trailing newline)
Oo / 42 -> 42
Op / 42 -> *
1cNoo -> 11
no -> 0
Ogo / 2 -> 2
Ogoi / -4 -> (newline)
50a -> (no output)
On12co / 12 -> 2
Clarifications
- The input to your interpreter will be a valid simplified 33 program.
- The input may be given in any acceptable format.
- The output may be given in any acceptable format.
- When dividing, truncate any decimal places.
- A trailing newline is acceptable, but it must be consistent; as in, if there's an
i
at the end of the program, it should have two trailing newlines. - The accumulator and counter must be able to hold at least a signed byte (-128 to 127)
- You may assume that the
p
instruction will never be given when the accumulator has an invalid ASCII character in it. - You may assume the
O
instruction will never be given unless there is a valid integer string (such as3
,-54
,+23
) left in the input.
O
work? \$\endgroup\$o
outputs it \$\endgroup\$x-13
, willO
skip thex
and read the-13
? Or can we assume that there will always be an integer right where theO
reads the input? \$\endgroup\$+03
be valid input for integer? \$\endgroup\$