Skip to main content
edited tags
Link
NinjaBearMonkey
  • 10.4k
  • 3
  • 37
  • 66
Tweeted twitter.com/#!/StackCodeGolf/status/414661140854362112
Added relevant tag
Link
Justin
  • 21.3k
  • 9
  • 67
  • 114
Source Link
marinus
  • 31.2k
  • 7
  • 71
  • 112

Write an interactive Deadfish interpreter

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

  1. 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.
  2. 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
    
  3. If, after executing a command, the accumulator is either -1 or 256, the accumulator must be reset to zero. Note that this is not normal wrap-around. If, say, the accumulator is 20, and the s command is run, the accumulator should be 400 afterward. Similarly, if the accumulator is 257 and the d command is run, the accumulator should become 0.
  4. Any input that isn't one of these commands should be ignored.

Test programs

  • xiskso should output 0
  • xiskisc should output 289

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
>>