Deadfish
One number, four commands, no loops. It cannot compute much, and it has a famous bug that became the spec: 256 turns into 0.
Jonathan Todd Skinner, 2006 · Turing complete: no · ●○○ easy · esolangs.org
Tested with 9 examples · Test method
Run it
Four, then sixteen
Two i make 2, s squares it to 4, o prints 4. Squaring again gives 16.
Expected output
4 16
Output
- Each
oprints the number and a newline.
The idea
Jonathan Todd Skinner made Deadfish in 2006 as a deliberately tiny language. There is one accumulator and four letters to change or print it. There are no loops, no conditions and no input.
Read the story
That makes Deadfish plainly not Turing complete. Every program runs straight through once and stops. Its only puzzle is arithmetic: how do you reach a number in as few i, d and s steps as possible?
Its strangest rule came from the original C interpreter. A comment there claims to stop the value going over 256, but the code only resets it when it is exactly 256 or exactly -1. Implementations copy that behaviour on purpose. The bug is now the language.
The machine
One integer, starting at 0.
| Char | Does |
|---|---|
i | Add 1 |
d | Subtract 1 |
s | Square |
o | Print the number (one per line in the player) |
After each command, if the number is exactly -1 or exactly 256, it becomes 0. So 255 + 1 is 0, but 257 is fine, and squaring can take you far past 256. Some versions add h to halt. The original interpreter answers any other character with a newline; this implementation ignores it.
Example
Print 72 (the code for H).
Print 72 (the code for H). Squaring makes it short: 2, 4, 8, 64, 72.
ii 2
s 4
iiii 8
s 64
iiiiiiii 72
o print
The last two are from the esolangs.org list of test cases every implementation should pass.
Commands
| Command | What it does | Kernel tokens |
|---|---|---|
i | add 1 to the number | 0 LOAD 1 ADD fix 0 STORE |
d | take 1 from the number | 0 LOAD 1 SUB fix 0 STORE |
s | square the number | 0 LOAD DUP MUL fix 0 STORE |
o | print the number in decimal, then a newline | 0 LOAD num EMIT 10 EMIT |
The kernel keeps the number in memory cell 0. Two helper words do the work Deadfish needs and the kernel does not have.
fix => DUP 256 EQ OVER -1 EQ ADD IF DROP 0 THEN
num => [ ] SWAP BEGIN DUP 10 MOD 48 ADD rot CAT SWAP 10 DIV DUP NOT UNTIL DROP
rot => [ SWAP ] DIP SWAP
fixsets the number to 0 when it is 256 or −1. It adds the two tests and drops the number if either is true.numturns a number into its decimal digits as a list, by taking the last digit with10 MODagain and again.rotbrings the third value to the top.- The kernel itself knows nothing about 256; the dictionary says it.
Step by step
Two, four, sixteen, and then 16 squared is 256.
The reset at 256
Two, four, sixteen, and then 16 squared is 256. That is the reset value, so the number becomes 0 and o prints 0.
Expected output
0
Output
Classic programs
258 commands.
Classic 1
Expected output
4
Output
Classic 2
Expected output
0
Output
Classic 3
Expected output
16
Output
Classic 4
Expected output
0
Output
Classic 5
Expected output
0
Output
Classic 6
258 commands. Long runs of i are how Deadfish writes large numbers.
Expected output
255 0
Output
Classic 7
103 commands. Long runs of i are how Deadfish writes large numbers.
Expected output
158
Output
Quirks
- The reset. 256 and −1 become 0, and only those two values; 257 or −2 stay. A program that steps over 256 with
skeeps the big number. - No characters. Plain Deadfish prints only numbers. Deadfish~ adds
cto print a character and{}to repeat. - Unknown commands. The kernel skips any character it has no rule for. Some interpreters print a newline for each one.
- Stopping. Some Deadfish relatives have
hto stop. In the Deadfish substitutionshis read as the kernel’sHALT.
Try this
- Print 100 in as few commands as you can.
- Print 255, then 0, then 1, using only
iandoafter the first number. - Write a program that prints every number from 1 to 300 that is a perfect square. What happens near 256?
Patterns it teaches
- Turing completeness: a clean non-example. No way to repeat, so no way to run unboundedly; a program of length n does exactly n things.
- Every text runs: every string is a Deadfish program and every run ends. Deadfish gets both for free by having no loops at all.
Family and nearest relatives
10 languages are substitutions of Deadfish, for example Sakana, Pește mort, Numbered DeadFish, XKCD.
10 languages are substitutions of Deadfish, for example Sakana, Pește mort, Numbered DeadFish, XKCD. Deadfish~ is a relative with characters and repetition.
Further
- esolangs.org/wiki/Deadfish (with the test cases and implementations in hundreds of languages).
- Another language that exists mostly for its punchline: HQ9+.
Substitutions
10 languages rename Deadfish’s commands and change nothing else.
10 languages rename Deadfish’s commands and change nothing else.
See also
Accumulator-based
Write your own in Run Convert a program from Deadfish
Implementation
Kernel translation, .shib file and command line
Runs on the deadfish interpreter. Id: deadfish.
Command line
shib run deadfish -e 'iisiiiisiiiiiiiio'shib run shib:deadfish -e 'iisiiiisiiiiiiiio'shib manual deadfishKernel translation
| Command | Kernel instructions |
|---|---|
i | 0 LOAD 1 ADD fix 0 STORE |
d | 0 LOAD 1 SUB fix 0 STORE |
s | 0 LOAD DUP MUL fix 0 STORE |
o | 0 LOAD num EMIT 10 EMIT |
Kernel definition
#! shibboleth 3 seed=deadfish syllables= plain=off
Deadfish as a front end: the accumulator is memory cell 0; fix resets 256 and -1 to 0; num writes a number in decimal
"i" => 0 LOAD 1 ADD fix 0 STORE
"d" => 0 LOAD 1 SUB fix 0 STORE
"s" => 0 LOAD DUP MUL fix 0 STORE
"o" => 0 LOAD num EMIT 10 EMIT
fix => DUP 256 EQ OVER -1 EQ ADD IF DROP 0 THEN
num => [ ] SWAP BEGIN DUP 10 MOD 48 ADD rot CAT SWAP 10 DIV DUP NOT UNTIL DROP
rot => [ SWAP ] DIP SWAPSource
- Interpreter
tools/convert/languages.js- Kernel definition
shibboleth/witness/deadfish.shibonshibboleth/kernel.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org