esolang
Learn · Ideas1 language show it

Deadfish’s 256 reset

Deadfish sets its number to 0 at exactly 256 or −1. brainfuck wraps every value modulo 256. The two look alike and are not.

●○○ easy · where to see it

The idea

Deadfish has one strange rule. When its number becomes exactly 256 or exactly −1, it becomes 0. Only those two values do; 257 stays 257.

Read the story

brainfuck’s cells wrap instead, taking every value modulo 256. Both reach 0 from 256, so many short programs cannot tell them apart.

Step by step

4, then 16, then 256, which resets to 0.

16 squared is 0

4, then 16, then 256, which resets to 0.

Expected output

0

Output


17 squared is not reset

4, 16, 17, then 17 squared is 289. That is not 256, so it stays.

Expected output

289

Output


brainfuck wraps 289 to 33

A multiplication loop makes 17 times 17 = 289 in a cell. The cell keeps only 289 modulo 256 = 33, the character !.

Expected output

!

Output


How the kernel writes the rule

The kernel knows neither rule. The Deadfish dictionary adds a helper word, fix, after every change.

fix => DUP 256 EQ OVER -1 EQ ADD IF DROP 0 THEN

fix, written out in kernel tokens

Square 16, then test "is it 256?" and "is it −1?". Adding the two tests gives 1 if either is true; then the number is dropped and 0 pushed. 48 is added to print the digit.

Expected output

0

Output


What evolution invented

Shibboleth learned Deadfish from examples, with no manual.

Shibboleth learned Deadfish from examples, with no manual. One run learned the reset at 256 as "move to an empty cell".

"s" => PUSH; MULS; SKIPNE 256; MOVE 1

It squares the cell (push, then multiply by the popped copy), and if the result is 256 it moves to the next cell, which is still 0. The number is not reset; the machine looks somewhere else. Another run learned the reset at −1 as a double skip, "d" => SKIPNE 0; SKIPNE 256; ADD -1. Nobody wrote either rule.

See Deadfish and how a language can evolve.

Where to see it