A rewrite of this question with a simpler input format and guidelines.

## Challenge

Deadfish uses a single accumulator, on which all commands are to be performed.

It has the following commands:

Command Description
i increment the accumulator
d decrement the accumulator
s square the value of the accumulator
o output the value of the accumulator as a number

If, after executing a command, the accumulator is equal to -1 or equal to 256, the accumulator must be reset to zero.

## I/O

Input can be taken as a single string, list of codepoints, or any other reasonable format. It is guaranteed that the input will only consist of deadfish commands.

Output can be given as an array of numbers, or just the numbers printed with separators between them.

## Testcases

(some are borrowed from the Esolangs wiki)

iissso -> 0
diissisdo -> 288
iissisdddddddddddddddddddddddddddddddddo -> 0
isssoisoisoisoiso -> 1,4,25,676,458329
ooooosioiiisooo -> 0,0,0,0,0,1,16,16,16
iiii -> nothing
iiiiiiiissdiiiiiiiiiiiiiiiiio -> 4112
o -> 0


Without Outputs

• Can there be leading separators? – att Jan 30 at 22:41
• What if the accumulator exceeds 256? For example, 29^2? – Xcali Jan 31 at 1:12
• @Xcali the checks are only for -1 or 256, so nothing should happen in that case. – Razetime Jan 31 at 2:09
• @tsh As long as it satisfies the testcases, it is fine. The accumulator will stay within the maximum integer range of your language. – Razetime Jan 31 at 3:44
• diso tests every functionality of the code except for 256 – Gotoro Jan 31 at 14:52

# flex, 86 $$\\cdots\$$ 83 82 bytes

Saved 2 bytes and got moved into TIO thanks to Mukundan314!!!

%{
a;m(){a*=a!=256;}
%}
%%
i m(++a);
d m(a&&--a);
s m(a*=a);
o printf("%d ",a);
%%


Try it online!

flex stands for fast lexical analyser generator. It takes input as above and generates a lexer in C.

The input comprises of a C declaration section:

%{
a;m(){a*=a!=256;}
%}


where here we simply declare the accumulator a (implicitly as an int) and a function to set the accumulator to $$\0\$$ if it's $$\256\$$ after a computation.

This is followed by the rules section comprised of all the regexes that need to be parsed along with their actions (in C):

%%
i m(++a);
d m(a&&--a);
s m(a*=a);
o printf("%d ",a);
%%


here we have our 4 characters along with the code to run when each is encountered. Decrement will only happen if the accumulator is non-zero.

There's a program section that follows this but it will simply default to a main that runs the parser if left out (as in this case).

You can generate the C-source code lexer from the above (in file deadfish.l) and compile it with the following:

flex deadfish.l


After compiling, running the following:

echo iissso | ./deadfish


outputs:

0
288
0
1 4 25 676 458329
0 0 0 0 0 1 16 16 16
4112


You can also just run it as ./deadfish and have an interactive deadfish environment to play with to your heart's content!

• 84 bytes – Mukundan314 Jan 31 at 13:49
• @Mukundan314 Nice one + thanks for getting it working in TIO! :D – Noodle9 Jan 31 at 13:58
• Why is the header linking to GNU Bash? – Wezl Feb 2 at 19:08
• @Wezl Because TIO doesn't handle flex directly but you can run via bash. – Noodle9 Feb 2 at 19:46

# convey, 90 76 bytes

 {"='i'
0+#<
^v"='d'
^-#<
^v"='s'
^*#+1
^.=<'o'
^>@
^}",
*<<"=256
.="*.
0-1


Try it online!

On the top right side, the input gets compared with idso. The result (0 or 1) then gets combined with the accumulator: a += c == 'i', a -= c == 'd', a = pow(a, (c == 's') + 1) (pow = *.), and o pushes a copy into the output @"}. At the bottom are the checks for -1/256, by calculating a *= a != 256 and a *= a != -1. Then the accumulator loops back to start the next round.

One iteration of the accumulator loop: # JavaScript (ES10), 66 bytes

Expects a list of codepoints.

a=>a.flatMap(n=>n%5?p:(p=(p=[p-!!p,p+1,,p*p][n&3])-256&&p,[]),p=0)


Try it online!

### How?

o is the only command whose codepoint ($$\111\$$) modulo $$\5\$$ is not equal to $$\0\$$. This is also the only command that requires a special operation that doesn't update the accumulator. That's why we first test that.

If the first modulo is $$\0\$$, we apply a modulo $$\4\$$ to distinguish between the other commands and update the accumulator accordingly.

 char. | code | mod 5 | mod 4
-------+------+-------+-------
'd'  |  100 |   0   |   0
'i'  |  105 |   0   |   1
'o'  |  111 |   1   |  (3)
's'  |  115 |   0   |   3


# Ruby, 60 58 bytes

Saved 2 bytes thanks to @Sisyphus

a=0;$<.bytes{|b|a=0if(a=eval'~-~p a*'[b%20/3,2]+?a)^256<1}  Full program that reads a string from STDIN and outputs to STDOUT, one number per line. Each operation on the accumulator a is carried out by evaling a 3-byte string. The third byte is always a. The first two bytes are extracted from the string ~-~p a* starting at index b%20/3: Op $$\b\$$ $$\\left\lfloor\frac{b\bmod20}{3}\right\rfloor\$$ eval d $$\100\$$ $$\0\$$ ~-a i $$\105\$$ $$\1\$$ -~a o $$\111\$$ $$\3\$$ p a s $$\115\$$ $$\5\$$ a*a The reset conditions on the accumulator, which might be written a==-1||a==256 in ungolfed form, are replaced by the single condition a^256<1 (^ is bitwise XOR) because negative accumulator values other than $$\-1\$$ are not possible. • This is really nice - I especially like how you use the - twice. It's two bytes shorter as a full program: Try it online! – Sisyphus Jan 31 at 6:34 • @Sisyphus Nice one, thank you. I feel like $< tends to fly under my global variable radar! – Dingus Jan 31 at 9:32

# Python 2, 838276 74 bytes

Thanks to dingledooper for spotting a bug and -6 bytes!
-2 bytes thanks to Mukundan!

Takes input as a list of codepoints.

a=0
for x in input():
a=[a-1,a+1,a,a*a][x/6%4];a*=a^256>0
if x%5:print a


Try it online!

• I think it should be [a-1,a+1,a,a*a] instead of [a-1,a+1,a*a,a]. – dingledooper Jan 31 at 1:47
• @dingledooper You're right, thanks a lot. Now fixed and all test cases included. – ovs Jan 31 at 8:07
• And here's a 6 byte improvement – dingledooper Jan 31 at 8:24
• @dingledooper I used a+a%~a before, but completely missed that it was possible here, thanks again. – ovs Jan 31 at 8:32
• 74 bytes – Mukundan314 Feb 1 at 2:32

# Nim, 104 bytes

var r=0
r=[r*r,r,r+1,r-1][28-c.ord div 4];r*=int (r xor 256)>0;if c=='o':echo r


Try it online!

Based on @ovs's amazing Python answer.

# Nim, 120114 109 bytes

var r=0
case c
of'i':r+=1
of'd':r-=1
of's':r*=r
else:r.echo
if r in[-1,256]:r=0


Try it online!

-5 bytes by taking inspiration from @Gotoro's Python answer

# Python 3, 120 95 bytes

n=0
for x in input():
if n in(-1,256):n=0
if"o"==x:print(n)
else:n=[n+1,n-1,n*n][ord(x)%4^1]


Try it online!

Brought it down by 25 bytes thanks to Danis suggestion!

Using bit manipulation ^ we choose from the list of possible operations. Original suggestion used ord(x)%4^2 which yielded 0,1,2,3 for indexes and required the use of an additional 0 in the list at the index 0;

using ^1 instead yields 0,1,2, which allows to save 2 bytes in comparison.

Maybe it is possible to account for that additional 0 and use it as a condition to print o instead.(?)

• Welcome to PPCG! You can save 10 bytes by making it a full program and 1 byte by changing a**=2 to a*=a: Try it online! – xigoi Jan 30 at 22:58
• 116 bytes – caird coinheringaahing Jan 30 at 23:52
• @Danis your suggestion doesn't work, as else in the end only connects to if "s", which will output an answer every time it is not an "s". I've added elifs to it, bringing it down to 106 bytes in the end, thank you! – Gotoro Jan 31 at 7:34
• 86 bytes – Mukundan314 Jan 31 at 11:30
• 80 bytes based on Mukundan's suggestion. This uses the way chained comparisons are evaluated to get rid of the if/else statement. – ovs Jan 31 at 14:49

# AWK, 55 53 52 51 bytes

Thanks to user41805 for removing awk flags

Expects each operation to be on a separate line

{a*=a!=256}/i/{a++}/d/{a&&a--}/s/{a*=a}/o/{print+a}


Try it online!

## Explanation

{a*=a!=256}    # Before each operation multiply a by 0 if it equals 256
/i/{a++}       # If line contains 'i' increase a by 1
/d/{a&&a--}    # If line contains 'd' and a is non-zero decrement a by 1
/s/{a*=a}      # If line contains 's' square a
/o/{print+a}   # If line contains 'o' output a

• Ah, I see, Awk uses doubles so they would end up at infinity. – EasyasPi Jan 31 at 3:29
• Nice! Feeding the commands separated by "\n" was a good idea. I think you need to move the first clause (the 0/256) check to after the "s" code and before the "o" code though. Otherwise it might print "-1" or "256" if the operations are lined up just right. – cnamejj Jan 31 at 8:02
• @cnamejj That would only be a problem if the operators were not separated by a newline – Mukundan314 Jan 31 at 8:14
• You can remove the flags if you use print+a at the end – user41805 Jan 31 at 9:54

# ><>, 81 bytes

0v~$?$0+{="Ā":}=-10<
l<n:oav?="i"{v?="d"}:{v?="s"}:{;?=1
{~:*1->  2+0}>{~1-:v  >


Try it online!

Branching is the kryptonite of ><> terseness, so the golfiness here was creating a branchless -1 and 256 check ~$?$0+{="Ā":}=-10 backwards on the first line to get rid of whitespace. The s, i and d commands also feed into each other to make the layout manageable.

# 05AB1E, 2322 21 bytes

-1 -2 bytes thanks to Command Master!

Takes input as a list of codepoints.

õ?Îv">n<="y;è.VD₁^0›*


Try it online!

Commented:

õ?                  # print the empty string without a trailing newline
# this is necessary to disable implicit output if no 'o' is in the code
Î                 # push 0 and the input
v                # iterate over the instructions y in the input:

">n<="              # push string literal ">n<="
# These are the instructions in 05AB1E equivalent to "isdo"
y             # push the current instruction
;            # halve the instruction
è           # modular index into the instruction string
.V        # execute the instruction
D       # duplicate the current value
₁^     # XOR with 256
0›   # is this larger than 0?
*  # multiply the result with the current value
# x*(x^256>0) maps negative numbers and 256 to 0


# Retina, 61 bytes

\bi()|#?\bd|^(#*)s
$#1*#$.2*$2 ^#{256}\b m}^(#*)o$.1¶$1 #  Try it online! Link includes test cases, although they can be a bit slow (I think #?\bd is the slow case, but I'm not sure). Explanation: \bi()|#?\bd|^(#*)s$#1*#$.2*$2


Handle the i, d and s cases by inserting a # (for the i case), deleting an optional # (for the d case, also handling a d of 0) or squaring the number of #s (for the s case).

^#{256}\b



But if the value is exactly 256, then set it back to 0 (assuming that there's another operation, otherwise the remaining #s are ignored anyway).

^(#*)o
$.1¶$1


Handle the o case by prepending a decimal copy of the current number of #s on a previous line.

m}


Evaluate the above stages until there are no more letters to process; also turn on multiline matching for all of the stages.

#



Delete any remaining accumulated unary value.

# Charcoal, 37 bytes

≔⁰θＦＳ«Ｆ№⟦²⁵⁶±¹⟧θ≔⁰θ≡ιi≦⊕θd≦⊖θs≧Ｘ²θ⟦Ｉθ


Try it online! Link is to verbose version of code. Explanation:

≔⁰θ


Initialise the accumulator to 0.

ＦＳ«


Loop over the commands.

Ｆ№⟦²⁵⁶±¹⟧θ


If the list (256, -1) includes the accumulator...

≔⁰θ


... then set the accumulator to 0. (This is done before the operation because it's golfier, and doesn't change the result, since it still always happens between two operations, and whether it happens after the last operation isn't observable.)

≡ι


Switch on the current operation: ...

i≦⊕θ


... i means increment the accumulator; ...

d≦⊖θ


... d means decrement the accumulator; ...

s≧Ｘ²θ


... s means square the accumulator; ...

⟦Ｉθ


... otherwise print the accumulator on its own line.

# Wolfram Language (Mathematica), 60 bytes

Fold[<|i->#+1,d->#-1,s->#^2,o:>Echo@#|>@#2/.-1|256->0&,0,#]&


Try it online!

Input a list of symbols.

# Jelly, 25 24 bytes

:4ị⁾’‘;⁾Ṅ²¤j“-,⁹¤i¬×Ʋ”VZ


Try it online!

Interprets a Deadfish program given as a list of codepoints in a command-line argument, printing newlines between the numbers, then crashes with a TypeError.

Without the last two characters, it's a Deadfish to Jelly transpiler.

## Explanation

:4ị⁾’‘;⁾Ṅ²¤j“-,⁹¤i¬×Ʋ”VZ   Main monadic link
:4                         Integer divide by 4
ị                        Index into
⁾’‘;⁾Ṅ²¤                  "’‘Ṅ²"
’                          Decrement
‘                         Increment
Ṅ                      Print with newline
²                     Square
j               Join with separator
“-,⁹¤i¬×Ʋ”       "-,⁹¤i¬×Ʋ"
-,⁹¤              [-1, 256]
i             Find 1-based index
¬            Negate
×           Multiply by the number
Ʋ          Group this into one instruction
V    Evaluate (implicitly starting with 0)
Z   Zip — a number can't be zipped,
so this crashes the program in order to
suppress the implicit output

• – caird coinheringaahing Jan 30 at 23:41
• @cairdcoinheringaahing Unfortunately that doesn't work, because we need to return 0 (not 1 or 2) when the number is in the list. – xigoi Jan 31 at 10:19

# Arturo, 80 bytes

$[p][r:0loop p'c[do[[r:r*r][print r][r:r+1][r:r-1]]\28-c/4if or? r<0r=256[r:0]]]  A function that takes an array of codepoints and prints numbers separated by newlines. • I'm looking forward to the moment when arturo-lang.io will be working. – Galen Ivanov Feb 2 at 13:14 • @GalenIvanov Yeah, me too. – xigoi Feb 2 at 13:15 • BTW, do you use Red or Rebol? – Galen Ivanov Feb 2 at 13:19 • @GalenIvanov I looked at Red and found it interesting, but I've never used it. – xigoi Feb 2 at 13:25 • OK, thank you, xigoi! – Galen Ivanov Feb 2 at 13:30 # Husk, 26 25 bytes tGF₅0hx'o S&≠256!ë→a□?←0c  Try it online! ### Explanation The first line is the main program, the second line an helper function that computes the output of a Deadfish command that could be 'i', 'd' or 's'. Let's start from the first line: tGF₅0hx'o x'o Split the string on each 'o' h and discard the last part (we don't care what happens after the last 'o') G 0 Scan this list of strings using 0 as initial value F₅ computing the result of each Deadfish subprogram t Discard the first value (0)  What we are doing here is splitting the Deadfish code into the subprograms preceding each output 'o', and then computing the result of each subprogram. The result of a subprogram is computed by folding the helper function over the commands: the fold will start with the value of the accumulator coming from the previous subprogram (initially 0), and will apply the helper function to the next command and the accumulator to generate the new value for the accumulator. Lines in a Husk program are zero-indexed and modular: referring to line ₅ here is effectively the same as referring to line ₁, but the number of times we "loop around" back to the first line determines how the called function should be modified (in order argdup,flip,map,zip,hook); in this case we loop around 2 times, so we flip the helper function, passing the command ('i','d',or 's') first, and the accumulator second. We chain together the interpretations of the subprograms by scanning over the list of subprograms. A scan G is the same thing as a fold F, except it returns all partial results instead of only the final one. We explicitly set 0 as the initial value, but then the result of each subprogram will be passed as the accumulator to the next subprogram. The initial value is always part of the output for a scan, so we have to discard it at the end (t). So, how does the helper function compute the result of a Deadfish command? S&≠256!ë→a□?←0c Takes a character (one of "ids") and an accumulator, returns the new value for the accumulator c Convert the character to its codepoint value !ë and use it to index into this list of four functions: → Increment a Absolute value (dummy) □ Square ?←0 If nonzero then decrement else return 0 S&≠256 Return the result if ≠256, else 0  The trick here is that ord(c)%4 will return a different value for each c in "ids" (respectively 1,0,3). List indexing in Husk is modular so by indexing with this value into the list of functions we will get the function we need. a is there only to pad the list to 4 elements (because otherwise 's' and 'd' would have the same value modulo 3). We check for -1 by only decreasing the accumulator if its value is not 0, and we check for 256 explicitly after any command. # MathGolf, 23 bytes 0ÿ)²(o▒ê½§"_♠bαm¡╓*"u~╘  Input as a list of codepoint integers. Try it online. Explanation: 0 # Start with 0 ÿ)²(o # Push 4-char string ")²(o" ▒ # Convert it to a list of characters: [")","²","(","o"] ê # Push the input-list of codepoint integers ½ # Integer-divide each by 2 § # Index (modulair 0-based) them into the list of characters "_♠bαm¡╓*"u # Join these characters with "_♠bαm¡╓*" delimiter ~ # Execute the entire string as MathGolf code ╘ # Discard everything left on the stack (which otherwise would be # output implicitly) ) # Increase by 1 ² # Square ( # Decrease by 1 o # Print without popping _ # Duplicate the top of the stack ♠bα # Push 256, push -1, wrap them in a list: [256,-1] m # Map over both of them: ¡ # And check that they're NOT equal to the value we've duplicated # (0 if the duplicated value is -1 or 256; 1 otherwise) ╓ # Pop and get the minimum of this list * # Multiply it to the value  # AWK, 83 81 bytes Thanks to Dominic van Essen for shaving off 2 bytes... {for(;c=$++b%9;)printf c-3?(d=(x=c-6?c-1?d*d:--d:++d)<1?0:x==256?0:x)?f:f:+d"\n"}


This is pretty brute force, but it's ugly enough that I wanted to submit it. :) It's mostly abusing ternaries to save characters.

The input is code points separated by spaces as commandline arguments. The code converts them to modulo-9 to shorten the comparisons to the specific command values.

There's a minor trick on the printf line that might be worth highlighting.

printf c-3?..not-a-print-command..:d"\n"


prints the accumulator value when a o command is found.

The logic in the "truthy" part updates the accumulator, but always returns a value of f. Since that's a uninitialized variables, AWK picks a value based on the content where it's used. In this context it turns into a null string, so printf doesn't produce any output for non-o commands.

The code to update the accumulator is bundled into the print statement, so it's only called for a, d, i, and s commands. As result it doesn't have to check for o.

Try it online!

• I don't think you need to initialize d=0 if you output +d to specify a numeric 0 (rather than null string) for undefined value. Try it... – Dominic van Essen Jan 31 at 22:46

# C (gcc), 92 91 bytes

Thanks to ceilingcat for the -1.

Converts each operation into the range [0,3] to simplify the decoding process.

a,b;f(char*s){for(a=0;b=*s++/2;a*=a-256&&~a)(b&=3)?--b?--b?printf("%i ",a):a--:(a*=a):a++;}


Try it online!

# x86-16 machine code, 45 43 bytes

Source-compatible with x86 and x86_64.

Fails one test due to integer overflow, but instructions are given to switch it to 64-bit arithmetic in the demo.

00000000: 31 d2 ac 3c 64 72 23 74 0d 3c 69 74 0c 3c 6f 92  1..<dr#t.<it.<o.
00000010: 74 0a f7 e0 eb 07 4a eb 05 42 eb 02 ab 92 85 d2  t.....J..B......
00000020: 78 de 81 fa 00 01 74 d8 eb d8 c3                 x.....t....


        // "//" comments are solely for syntax highlighting
// sed -i -e 's#//#;#g' deadfish.asm
// nasm compatible
[bits 16]
[cpu 8086]
// Input:
//    si: input, null terminated string
//    di: output, uint16_t array
// Output:
//
//    di: points past the last value in the array
.Lzero:
// Set accumulator to 0
xor     dx, dx
.Lloop:
lodsb
// Check for null terminator and for 'd'
cmp     al, 'd'
// Below means null terminator, return
jb      .Lret
// equal means 'd'
je      .Lop_d
// check for 'i'
cmp     al, 'i'
je      .Lop_i
// check for 'o'
cmp     al, 'o'
// Since O and S both need AX instead of DX, xchg here.
xchg    dx, ax
je      .Lop_o
// assume 's'
.Lop_s:
// Square
mul     ax
// Jump to the end of the o code to swap AX to DX.
jmp     .Lnext_xchg
.Lop_d:
// Decrement
dec     dx
jmp     .Lnext
.Lop_i:
// Increment
inc     dx
jmp     .Lnext
.Lop_o:
// Output
// *di++ = ax
stosw
// Swap dx and ax again for o and s
.Lnext_xchg:
xchg    dx, ax
.Lnext:
// Check for -1 (less than zero) and 256
// If equal, jump to the xor dx, dx conveniently placed before the loop
test    dx, dx
js      .Lzero
// Literally the only reason I am using 16-bit is this instruction :P
cmp     dx, 256
je      .Lzero
jmp     .Lloop
.Lret:
// Return
ret


The input is a null terminated string in si, and the output is stored to the uint16_t array in di.

di will point to the end of the array to indicate the length (C++ <algorithm> style)

Try it online! Uses GAS Intel syntax because I want to use libc with it, and uses macros for registers to make it possible to switch to 64-bit arithmetic.

# PHP, 136 bytes

<?php $w=0;foreach(str_split($argv)as$v){if($v=='o'){echo$w.' ';}else{$w=$v=='s'?$w**2:($v=='i'?++$w:--$w);}if($w==256||$w<0){$w=0;}}


Example explained:

$w=0; #declare w var, is accumulator foreach(str_split($argv)as$v){ # for each char of first CLI argument if($v=='o'){                            #if output
echo$w.' '; #output w }else{ #otherwise$w=                                     #set w to
$v=='s'? #if input is s$w**2                                   #squared
:($v=='i'? #otherwise if incremented ++$w:                                   #add one
--$w);} #otherwise subtract one if($w==256||$w<0){$w=0;}}               #if -1 or 256 set 0


PHP is annoying for this. Is run php deadfish.php <program>

Note: run on CLI so no online example.

# Red, 106 bytes

func[s][a: 0 parse s[any[(if a xor 256 < 1[a: 0])"i"(a: a + 1)|"d"(a: a - 1)|"s"(a: a * a)|"o"(print a)]]]


Try it online!

Pretty simple solution :

f: func[s][
a: 0
parse s[
any[
(if a xor 256 < 1[a: 0])
"i"(a: a + 1)
|"d"(a: a - 1)
|"s"(a: a * a)
|"o"(print a)
]
]
]


# PowerShell, 68 bytes

switch -r($args){i{$a++}d{$a--}s{$a*=$a}o{+$a}.{$a*=$a-notin-1,256}}


Try it online!

# Pyth, 59 bytes

FNz=T%CN4IqN"o"Z=tT)IqT1=hZ)IqT0=tZ)IqT3=*ZZ)I}hZ[0 257)=Z0


Try it online!

Bit out of practice. :)

# Stax, 37 35 bytes

ï☺C£q▒▒v¡ñ|≥íHQ3╤Ä╫Q,§╪c(>∙α._A↓ö≈/


Run and debug it

I only need one more byte to not blow up on a trailing newline in the input

saved two bytes thanks to Razetime

• 0s can be Z – Razetime Feb 2 at 2:44
• cP can be Q – Razetime Feb 2 at 2:47
• {d0} can be replaced with 0 since we're not worried about filling up the stack – Razetime Feb 2 at 2:49
• With those adjustments, it gets to 30(25 packed) – Razetime Feb 2 at 3:00
• @Razetime: I'm not actually very good at golfing. I just know a subset of stax inside and out because I wrote a metacircular compiler for it but never got around to implementing the rest of the instructions. – Joshua Feb 2 at 3:59

$args|%{switch($_){i{$x++}d{$x--}s{$x*=$x}o{+$x}}$x=1+$x-and$x-256?$x :0}  Link is to a slightly longer PS 6 solution, as TIO does not yet have PS 7. Try it online! # J, 64 bytes g=:0:^:(e.&_1 256) i=:g@>: d=:g@<: s=:g@*: o=:1!:2&2 f=:'0'".@|.@,]  Try it online! Note: -3 off TIO count for f=: This stores each Deadfish command in a variable of the same name, followed by the -1/256 check. Then we just prepend 0, reverse, and eval. Takes input with spaces between the letters. # Ohm v2, 30 bytes ÝL}7%5%›0s:_ΦD256â0>* › = ‹ ²  Try it online! • This is a really clever use of wires! – Nick Clifford Feb 17 at 15:47 # Icon, 106 bytes procedure f(s);a:=0 c:=!s&(if a:=[a+1,a-1,a*a][find(c,"ids")]then 1>ixor(a,256)&a:=0 else write(a))&\z end  Try it online! # PowerShell, 118 bytes $args|% t*y|%{if($a-in@(-1,256)){$a=0}if($_-eq'i'){$a+=1}elseif($_-eq'd'){$a-=1}elseif($_-eq's'){$a=$a*$a}else{\$a}}


Try it online!