Deadfish is a joke "programming language" with four commands. Because the Esolang page is a bit contradictory and the interpreters on that page don't all work exactly the same, you should implement the following variation:
Specification
- There is an accumulator which is at least 16 bits in size, more is allowed but less is not. Negative numbers do not need to be supported. The accumulator is
0
when the program starts. - There are the following two sets of four commands, and your program must support both at the same time.
Standard Deadfish │ XKCD Variant │ Meaning ─────────────────────┼──────────────────┼──────────────────────────────────── i │ x │ Increment accumulator d │ d │ Decrement accumulator s │ k │ Square ( acc = acc * acc ) o │ c │ Output accumulator, as a number
- If, after executing a command, the accumulator is either
-1
or256
, the accumulator must be reset to zero. Note that this is not normal wrap-around. If, say, the accumulator is20
, and thes
command is run, the accumulator should be400
afterward. Similarly, if the accumulator is257
and thed
command is run, the accumulator should become0
. - Any input that isn't one of these commands should be ignored.
Test programs
xiskso
should output0
xiskisc
should output289
I/O
Your program should display a prompt: >>
. The prompt must be at the beginning of a new line. It should then read a line of user input, and run the given commands left-to-right. When outputing numbers, the numbers must be separated. I.e., 12 34
is OK, 12,34
is OK,
12
34
is OK, but 1234
is not.
Your program should keep doing this in a loop, at least until EOF
is reached.
Example session:
>> xiskso
0
>> xiskisc
289
>> ddddo ddddo
285
281
>> ddddo ddddo
277
273
>> dddddddo
266
>> dddddddddo
257
>> do
0
>> do
0
>> io
1
>>
#{STDIN.gets}
would work but indeed it doesn't. \$\endgroup\$