30
5
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
>>
Are we allowed to take input with uppercase letters instead? – lirtosiast – 2015-07-04T20:06:09.357
I believe
d
is double, not decrement – SuperJedi224 – 2015-10-07T12:48:27.783Can we assume all statements will end with
o
orc
? – MayorMonty – 2016-07-31T17:46:49.327Because of the prompting for input, I can't use GolfScript :-( – ProgramFOX – 2013-12-22T10:04:13.553
@ProgramFOX: You can use ruby input right? – marinus – 2013-12-23T06:02:52.240
According to the GolfScript tutorial, you can't prompt for input in GolfScript, all input comes from STDIN. – ProgramFOX – 2013-12-23T08:22:44.337
@ProgramFOX: I would have thought something like
#{STDIN.gets}
would work but indeed it doesn't. – marinus – 2013-12-23T08:33:06.787