Please participate in the meta discussion about reopening this challenge before casting a vote.
Introduction
This challenge was inspired by semicolon-#.
Deadfish is a non-Turing-complete programming language, created by Jonathan Todd Skinner. It has an accumulator register and contains 4 commands, i
, d
, s
, and o
, standing for increment, decrement, square, and output, respectively. While this seems simple enough, the original implementation has some quirks that must be present in your interpreter.
Unlike a similar challenge here, this does not require the interpreter to be interactive.
Challenge
The challenge is to write a fully functional Deadfish interpreter, quirks included. The following requirements must be met:
- The accumulator must be more than 8 bits wide.
- When an
i
is encountered, increment the accumulator by 1. - When a
d
is encountered, decrement the accumulator by 1. - When an
s
is encountered, square the value of the accumulator. - When an
o
is encountered, print the value of the accumulator along with a newline. - When any other character is encountered, including control characters and whitespace but not a newline, print a newline.
- If and only if the accumulator equals
-1
or256
, set the accumulator to0
.
Test cases
From the esolangs article:
iissso -> 0
diissisdo -> 288
iissisdddddddddddddddddddddddddddddddddo -> 0
Rules
- Input may be accepted through STDIN or as argument(s).
- Standard loopholes are disallowed
- This is code-golf, so the shortest solution in bytes wins