Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Write a Deadfish Interpreter

+6
−0

A rewrite of this SE 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
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

8 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+2
−0

APL (Dyalog Classic), 47 bytes

i←+∘1⋄d←-∘1⋄s←×⍨⋄o←⎕∘←⋄{}{0⌈a×256≠a←⍎⍕⍺,⍵}/⌽0,⍞

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Lua 5.4.4, 99 bytes

_=0s:gsub('.',function(c)_=({d=_-1,i=_+1;s=_*_})[c]or print(_)or _ _=({[256]=0,[-1]=0})[_]or _ end)

Try it online!

Thanks to @orthoplex for more shortening.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Tables to the rescue ^^ ```lua _=0 for c in s:gmatch'.'do _=({d=_-1,i=_+1;s=_*_})[c]or print(_)or... (4 comments)
+2
−0

Vyxal D, 26 bytes

0Ȯ(n«ƛ√J«`›‹²…`ĿĖD₈=$0<∨[0

Try it Online!

0                          # Push 0
 Ȯ(n                       # Iterating over the input
    «ƛ√J«`›‹²…`Ŀ           # Transliterate into appropriate Vyxal instruction
                Ė          # Evaluate
                 D₈=$0<∨[  # If 256 or negative
                         0 # Push 0
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

JavaScript (Node.js), 80 bytes

f=a=>a.map(a=>(a&=6,a-2?a-6?c+=1-a/2:d+=c+' ':c*=c,c*=c!=-1&c!=256),c=0,d='')&&d

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

C (gcc), 153 bytes

a,b;f(char*s){for(char*c,*o="idso";*s;s++)for(c=o;*c;c++)*s==*c&&(b=c-o,a+=!b,a-=b==1,b==2?a*=a:0,b==3&&printf("%d%c",a,s[1]?44:10),a==-1|a==256?a=0:0);}

Try it online!

Function solution, misc gcc abuse.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

C (gcc), 98 bytes

_=0;f(char*s){for(;*s;++s)_==256||_<0?_=0:1,*s=='i'?_++:*s=='d'?_--:*s=='s'?_*=_:printf("%d ",_);}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Ruby, 70 67 66 bytes

->c{a=0;c.bytes{|b|a,=[b<106?a+b/3-34:b<112?p(a):a*a,0]-[-1,256]}}

Test this online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

You can shave off a byte by moving the `,0` into the first array and removing the `*`: `a,=[b<106?a+b... (2 comments)
+0
−0

JavaScript (V8), 78 bytes

f=s=>s.map(c=>(_==256||_<0?_=0:0)||c=='i'?_++:c=='d'?_--:c=='s'?_*=_:v+=_+' ')

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »