5
1
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.
How does
O
work? – Erik the Outgolfer – 2019-09-10T10:57:55.020@tsh Yes. I'll update that. – TheOnlyMrCat – 2019-09-10T10:59:10.720
@EriktheOutgolfer It reads the integer in the same format that
o
outputs it – TheOnlyMrCat – 2019-09-10T11:01:36.843@TheOnlyMrCat If the remaining input is
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? – Erik the Outgolfer – 2019-09-10T11:02:43.610What is acceptable format for an integer input the interpreter must handle? Will
+03
be valid input for integer? – tsh – 2019-09-10T11:21:22.257+
and-
are not valid commands in 33, and 33 only handles positive integers. – None – 2019-09-10T11:36:35.610@A_
The accumulator and counter must be able to hold at least a signed byte (-128 to 127)
– tsh – 2019-09-10T11:38:05.033I believe that is internally, not externally. – None – 2019-09-10T11:38:38.757
N12
should skip the1
command, since1
and2
are separate commands. – None – 2019-09-10T11:39:31.623Let us continue this discussion in chat.
– tsh – 2019-09-10T11:46:16.567@TheOnlyMrCat In the official 33 interpreter, trying to read an integer containing letters is invalid. You need to make the challenge self-contained and explain what an interpreter should do with this input. – None – 2019-09-10T11:49:38.293
How does
p
behave if the accumulator is negative? – ar4093 – 2019-09-10T12:03:23.080the example
1Noo
should output0
not11
. – tsh – 2019-09-10T12:05:44.953