4
\$\begingroup\$

This question already has an answer here:

Please participate in the meta discussion about reopening this challenge before casting a vote.

Introduction

This challenge was inspired by .

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 or 256, set the accumulator to 0.

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 , so the shortest solution in bytes wins
\$\endgroup\$

marked as duplicate by Stewie Griffin, AdmBorkBork code-golf Feb 16 '18 at 14:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ @dylnan This one doesn't impose an interactivity requirement, however, allowing more languages to be used \$\endgroup\$ – robbie Feb 15 '18 at 17:26
  • \$\begingroup\$ True. I think people will say you should make a meta post about it. If they say it's a good idea and you link to the meta post on this post then people will be okay with it. \$\endgroup\$ – dylnan Feb 15 '18 at 17:30
  • \$\begingroup\$ @Uriel yes it should! \$\endgroup\$ – robbie Feb 15 '18 at 17:40
  • \$\begingroup\$ Related meta post. \$\endgroup\$ – Mr. Xcoder Feb 15 '18 at 19:32
0
\$\begingroup\$

Proton, 114 bytes

a=0s={"i":(a=>a+1),"d":(a=>a-1),"s":(a=>a*a),"o":(a=>[print(a),a][1])}for i:input(){a=s[i](a)if a in[-1,256]{a=0}}

Try it online!

The fact that this even parses correctly demonstrates how weird Proton 1 is o_O

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.