Fishstacks is a deadfish derivative based on a stack the stack can only hold four elements when a fifth element is pushed the bottom element is kicked out and eventually printed out to the screen.
I've come up with an interpreter in TI-BASIC for my calculator. However, I fell slightly guilty about using all four variables ABCD
. I wonder if there could be a better way? Maybe with lists (arrays). I've just started learning about them, so I don't feel confident switching over yet. Any guidance would be appreciated.
Also, in order not to push anything to the screen until something falls off the stack, I've had to initialize variables to -2
. This is the main reason I have not converted to arrays yet; I don't see how they could address this issue. (maybe even throw a DOMAIN
error).
:ClrHome
:Disp "FISHSTACKS IDSP","INTERPRETER"
:0->I
:-2->A
:A->B
:B->C
:C->D
:Input Str1
:While I<length(Str1)
:I+1->I
:sub(Str1,I,1)->Str2
:If Str2="I"
:A+1->A
:If Str2="D"
:A-1->A
:If Str2="S"
:A^2->A
:If Str2="P" and D>-1
:Then
:Disp D
:C->D
:B->C
:A->B
:0->A
:End
:If A=256 or A=-1
:0->A
:If A=-2
:Stop
:End
By convention, I've represented the STO→
character, →
with ->