Confusion
It looks like C, but no number, name or operator means what it says.
Alessandro Morina, 2016 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Alessandro Morina made Confusion in April 2016, out of a challenge among his classmates. The code reads like a C program with registries, operators and blocks. Then every piece of it is shifted a little.
Read the story
A registry x is not written as x. It is written as F(x), which is 2x for an even x and 3x for an odd one, so registry 1 is called 3 and registry 2 is called 4. A number in the program is stored as two thirds of itself, so to store 100 you write 150. The operators are swapped around, and so are the comparisons.
The machine
There are 1,000,000 registries of doubles, all 0 at the start.
| Statement | Does |
|---|---|
R = (V); | Store two thirds of V in R |
R = R2; [R] = ...; | Copy a registry; write to the registry whose code R holds |
->(R, V1, V2, ...); | Fill R and the registries after it |
op(R, A, B); | Store A op B in R |
?(R) ... ?; | Run the body if R holds |
:>(R) ... <; | Repeat the body while R holds |
i(R); n(R); | Read a character or a number |
o(R); on(R); | Print a character or a number |
dne_eht; | End the run |
| Written | + | - | * | / | % | == | != | > | < | >= | <= |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Does | A % B | A * B | A + B | B - A | A / B | < | > | >= | != | <= | == |
A condition on R is false only when R's registry x holds 0 and the registry 10 places further holds x. So a loop needs a second registry set up to let it end. Numbers print with .0 when they are whole, as 7.0.
Example
The Hello World fills registries 0 to 7 with two cascades and prints them by their codes.
The Hello World fills registries 0 to 7 with two cascades and prints them by their codes. ->(0, 108, ...) stores 72, an H.
The simple sum stores 2 and 5, and adds them with *.
The factorial reads n into registry 1. Registry 11 holds 1, so the loop ends when n reaches 0. Inside it - multiplies and / subtracts 1.
The specification also solves the first problem of Project Euler, the sum of the multiples of 3 or 5 below 1000. It prints 233168.0.
Patterns it teaches
- Hostile design: every familiar symbol is kept and its meaning moved.
Further
See also
Also in Hostile
Write your own in Run Convert a program from Confusion
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: confusion.
Command line
shib run confusion -e 'i(0);
o(0);' --input 'a'shib manual confusionSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/confusion.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org