Hardfish
Deadfish without a decrement. Every number is reached through steps that look like the Collatz map.
2017 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Hardfish is a Deadfish variant from 2017. Deadfish can add 1, take 1 away and square. Hardfish keeps the add and gives the rest up for two jumps. c halves an even number and makes 3n+1 of an odd one, the step of the Collatz problem. q divides a multiple of 3 by 3 and makes 2n+1 of any other number. No command may come twice in a row, so ii is not a program, and getting to a number means steering between the two jumps.
Read the story
The fifth command, r, runs every command before it again and then vanishes. The specification has two tables of the shortest program for each number, one with r and one without, 993 programs in all. Every one of them gives its number.
The machine
| Command | Does |
|---|---|
i | Add 1 |
c | n/2 when n is even, 3n+1 when odd |
q | n/3 when 3 divides n, 2n+1 when not |
r | Run every command before it again, then vanish |
o | Print the value as a character |
The value starts at 0 and becomes 0 again when it lands on exactly 256, which keeps it compatible with Deadfish.
Example
The Hello World uses no r.
The Hello World uses no r. Its first eight commands, iqciciqi, climb from 0 through 1, 3, 10, 11, 34, 35 and 71 to 72, and o prints H.
With r. i and c make 1 and then 4, r runs ic again for 5 and 16, q makes 33, and o prints it as !.
The specification explains r with icricr, which it says runs as ic ic icic. Its own table gives 484 for that program, and that is what ic ic ic icic makes. The first r runs ic again, and the second runs icic, since the first r is gone by then. This implementation follows the tables.
Patterns it teaches
- Encoding tricks: each letter of a text is a short search through halving, tripling and doubling.
Further
See also
Hardfish builds on Deadfish~.
Deadfish derivatives
Write your own in Run Convert a program from Hardfish
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: hardfish.
Command line
shib run hardfish -e 'icricr'shib manual hardfishSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/hardfish.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org