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

Post History

66%
+2 −0
Challenges Write a Deadfish Interpreter

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.

posted 2y ago by Zakk‭  ·  edited 2y ago by Zakk‭

Answer
#2: Post edited by user avatar Zakk‭ · 2022-04-25T16:08:08Z (over 2 years ago)
shortened the code (thanks to orthoplex)
  • # [Lua 5.4.4](https://lua.org), 131 bytes
  • ```
  • _=0 for c in s:gmatch'.'do if _==256or _<0then _=0 end _=c=='i'and _+1or c=='d'and _-1or c=='s'and _^2or c=='o'and print(_)or _ end
  • ```
  • [Try it online!](https://tio.run/##hY/BDoIwEETv/Yq9LUQwSKIHY39FQijIRqWErSfjt2PXghAvTpp03u5kmt4e5ehqdqDhqcALiZjZYhLICBKb72Dif1ry0karMy@siMmSb/Ru6SdaexGzoV8tPaheSjV2gGsCDNRBX9LAkfwqBmNVP1DnIo7HQmcguUpCfLzcS1e1uEVjgRootM73B78uTplr6w4kXnfG35XWSFiK3@ykwLMJnM7Mgc/5xPbD4e0illopG8MA00kYK5m@AQ)
  • ----
  • Another version, 131 bytes:
  • ```
  • _=0 s:gsub('.',function(c)if _==256or _<0then _=0 end _=c=='i'and _+1or c=='d'and _-1or c=='s'and _^2or c=='o'and print(_)or _ end)
  • ```
  • [Try it online!](https://tio.run/##hY/BCsIwDIbvfYrcsuIUHehB7Ks45rppUFpZupP47LOx0w0v/hSaLw1f6K2vhtBwAAMPBTFIxMwe80RWkNh@GyP/yzQvNpqdz4OXMHmKxlhNfqJ5LWG29JvJg@qpVOs7uObAQA7uFXWcya80WK/uHbmQsR5Kswben7k/ZbjCvO1dHci7rNbUQmlMsd1FS3lYh0vjQKYbZ@NdG4OEldSLTZwQtomXH@bEx2Jk/@a0utSiFZkeUgeXY1Cr2B5e)
  • # [Lua 5.4.4](https://lua.org), 99 bytes
  • ```
  • _=0s:gsub('.',function(c)_=({d=_-1,i=_+1;s=_*_})[c]or print(_)or _ _=({[256]=0,[-1]=0})[_]or _ end)
  • ```
  • [Try it online!](https://tio.run/##hY/BCsIwEETv@Yq9JdFUrKAHJV9SyqKNyqIkpdueSr@9JlatePERyMzuZCD37ji2Z27BQi8gIomYOUgzOZcssfsMXv4fcz610dd5L0KCKVBsjGruJ/rWCWZHv8w9UgxCXEIDNwMM5KE@UsMq/UqDC6JuyLeK9Yh2zfsrdyclV9JcOl@1FLyqNFrVO4tZbsjiMj@wxQUOuqjK2Do9Rx0lQkoWm@2utGtTZHm8YgzL5@7snR6ntMxeSC3ieHwA)
  • Thanks to [@orthoplex](https://codegolf.codidact.com/users/56271) for more shortening.
#1: Initial revision by user avatar Zakk‭ · 2022-04-24T21:51:13Z (over 2 years ago)
# [Lua 5.4.4](https://lua.org), 131 bytes

```
_=0 for c in s:gmatch'.'do if _==256or _<0then _=0 end _=c=='i'and _+1or c=='d'and _-1or c=='s'and _^2or c=='o'and print(_)or _ end
```

[Try it online!](https://tio.run/##hY/BDoIwEETv/Yq9LUQwSKIHY39FQijIRqWErSfjt2PXghAvTpp03u5kmt4e5ehqdqDhqcALiZjZYhLICBKb72Dif1ry0karMy@siMmSb/Ru6SdaexGzoV8tPaheSjV2gGsCDNRBX9LAkfwqBmNVP1DnIo7HQmcguUpCfLzcS1e1uEVjgRootM73B78uTplr6w4kXnfG35XWSFiK3@ykwLMJnM7Mgc/5xPbD4e0illopG8MA00kYK5m@AQ)

----

Another version, 131 bytes:

```
_=0 s:gsub('.',function(c)if _==256or _<0then _=0 end _=c=='i'and _+1or c=='d'and _-1or c=='s'and _^2or c=='o'and print(_)or _ end)
```

[Try it online!](https://tio.run/##hY/BCsIwDIbvfYrcsuIUHehB7Ks45rppUFpZupP47LOx0w0v/hSaLw1f6K2vhtBwAAMPBTFIxMwe80RWkNh@GyP/yzQvNpqdz4OXMHmKxlhNfqJ5LWG29JvJg@qpVOs7uObAQA7uFXWcya80WK/uHbmQsR5Kswben7k/ZbjCvO1dHci7rNbUQmlMsd1FS3lYh0vjQKYbZ@NdG4OEldSLTZwQtomXH@bEx2Jk/@a0utSiFZkeUgeXY1Cr2B5e)