Uzumaki

From Esolang
Jump to navigation Jump to search
Uzumaki
Paradigm(s) imperative
Designed by User:Zero player rodent
Appeared in 2022
Memory system Queue-based
Dimensions two-dimensional
Computational class Turing complete
Reference implementation Github
File extension(s) .uzu

Spirals... This language is contaminated by spirals...

Uzumaki is a queue-based 2D esoteric programming language created by User:Zero player rodent. It was designed so that the code would flow in the shape of a perfect spiral. It was inspired by Junji Ito's horror manga series "Uzumaki".

Details

Uzumaki is a two-dimensional language, meaning the instruction pointer can move in a two-dimensional space.

Uzumaki uses an unbounded queue and unbounded accumulator for memory, and both can hold unbounded positive or negative integers (and 0). The accumulator is set to 0 by default, and the queue initializes with a single 0 enqueued.

When Uzumaki encounters an invalid instruction, it will return an error and terminate.

For every program, the source code's width has to match its height, meaning every program must be a "perfect" spiral. Note that the interpreter is very picky about this, so if there's even a single stray byte the program won't run. Try highlighting your code to check for any rogue bytes when debugging.

Program structure

In Uzumaki, the IP moves in the pattern of a spiral. When it reaches the "center" of the spiral, (when the spiral can't curl any further) the program will terminate. Each spiral must be curled to the maximum amount.

Control flow is achieved by making the IP jump between the different "layers" of the spiral. The initial layer of the spiral is layer 1, and every time the spiral curls into itself the current layer increments. Each layer is separated by 1 byte in the middle. The IP jumping "outwards" means decrementing the layer that the IP is on, and jumping "inwards" means incrementing it. You can also make the IP jump inwards and land on the same layer if it is not aligned with an inner layer.

Whenever the IP jumps inward, it moves in the cardinal direction that would get it closer to the center of the spiral. When the IP jumps outward, the inverse is true. For example, if the IP was moving up and jumped inwards, it would move right until it reaches code to execute.

Below is an illustrated example of the program structure. The arrows indicate the direction of the IP for each byte, and the number above each layer indicates which layer it is. The X indicates where the program will terminate.

  1
>>>>>>>>>v
  2      v
>>>>>>>v v
^ 3    v v
^ >>>v v v
^ ^  X v v
^ ^    v v
^ ^<<<<< v
^        v
^<<<<<<<<<

Code comments can be placed in-between layers.

Commands

Command Outcome Can queue be empty
# Output every character between the next #. Yes
Q Enqueue 0. Yes
I Increment front of queue. No
D Decrement front of queue. No
P Add 10 to front of queue. No
M Subtract 10 from front of queue. No
O Output value in front of queue. No
C Output value in front of queue as ASCII character. No
A Set accumulator to value in front of queue. No
X Dequeue. No
Z Duplicate. (enqueue value in front of queue) No
S Enqueue byte of input. If there is no input to enqueue, enqueue 0. Yes
V Add accumulator to front of queue. No
W Set layer of IP to layer 1 Yes
J Move IP forward if queue equals accumulator. No
K Move IP forward if queue does not equal accumulator. No
R Reverse queue. (Back becomes front, front becomes back) Yes
H Make IP jump outward, and immediately execute command it lands on. Yes
B Make IP jump inward, and immediately execute command it lands on. Yes
E Output the entire queue. No
G Gets line of input. If the input is an integer, enqueue it. Otherwise enqueue 0. Yes

Computational class

Uzumaki is Turing complete, due to its capability to simulate other Turing complete languages or systems.

Cyclic tag system simulation

Uzumaki is capable of simulating any arbitrary cyclic tag system. To construct a cyclic tag system in Uzumaki, you must use the top part (the part where the IP moves right) of the first layer to initialize the data string with the desired 1s and 0s. Then we are free to use the rest of layer 1 and the top part of layer 2 for our productions. You can use the output commands as NOOPs because a language does not need functioning I/O to be Turing-complete, meaning output can be completely ignored. Use the table below to translate your productions into Uzumaki.

Cyclic tag system Corresponding Uzumaki code
1
JZ
0
JQ
End of production
XAJBQRAXR

(Note that you will need to make sure that the B commands are aligned with the next layer, and are not on a corner.)

After your productions are translated, use an H command to cycle back to the first production.

Here is the cyclic tag system with productions 011, 10, 101 and data string 1 translated to Uzumaki. (With added E commands so you can see each iteration.)

IEQRAXRRRRRRRJ
             Q
AJBEQRAXRHOO J
X          O Z
Z OOOOOOOO O J
J O      O O Z
Q O OOOO O O X
J O O  O O O A
Z O O    O O J
J O OOOOOO O B
R O        O E
X OOOOOOOOOO Q
A            R
RQEBJAXQJZJRXA


Translation from Brainpocalypse

You can translate any minimized Brainpocalypse program into Uzumaki. This is because you can simulate a bounded tape using a single queue. To convert any arbitrary minimized Brainpocalypse program to Uzumaki, you must first reserve the top part of layer 1 of the spiral for initializing the queue with 256 (or more) zeroes. This means you cannot write any translated Brainpocalypse commands on layer 1, or the top part of any layer. Then you must use an appropriate number of NOOPs in the form of output commands to pad the spiral for the intended size. Then you convert each minimized Brainpocalypse command to its Uzumaki equivalent using the table below.

Minimized Brainpocalypse command Corresponding Uzumaki code
}
ZXI
-
KWD

Below is an example of the minimized Brainpocalypse program }}-- converted to Uzumaki. (Note that this program is initialized with a queue size of 16 for the sake of keeping it small on the wiki page)

QQQQQQQQQQQQQQQ
              O
OOOOOOOOOOOOO O
O           Z O
O OOOOOOOOO X O
O O       O I O
O O OOOOO O Z O
O O O   O O X O
O O O OOO O I O
O O O     O K O
O O OOOOOOO W O
O O         D O
O OOOOOOOODWK O
O             O
OOOOOOOOOOOOOOO

Note that if you output the queue it will not be in the order of a tape, but instead in the order of an equivalent queue, with the leftmost element being the one that the tape pointer would be pointing to.

Example programs

Truth-machine

XGOR
   R
R  R
RRBJ

Hello, World!

#Hell
    o
#DD ,
!    
dlroW

Reverse cat

PAAARS
     Q
CRRJ R
X  B I
R    X
XIRQBJ

(Expects a newline after input)

Fibonacci sequence

RROQRPCX
       R
OQRPCX Q
V    R R
D R  A I
I HXAZ O
R      Q
AAARXCPR

This can be trivially altered to calculate Lucas numbers by replacing the RR at the beginning with II.

Collatz Conjecture

XGZZDKBIRRI
          D
RRHRRRBRR D
R       R K
R HRRRR X B
R X   R R R
R C RRR X D
R P     A D
R ARQOIVV R
R         R
RXCPRQOXXBJ

Input a number, and it will calculate the 3n+1 problem until it reaches 1.

(This program runs slowly when calculating large numbers)

99 Bottles of Beer on the Wall

PPPPPPPPPIIIIIIIII
                 R
s of beer! You t R
e              a R
l ottles of be k R
t B          e e R
t   RRRRRRRJ r   R
o # R      W   o O
B O R er.# # o n #
  D X e  R N n e  
# # C b    o     B
O   P  erom  t d o
# , R        h o t
  d Q# !llaw e w t
, n            n l
l uora ti ssap , e
l                s
aw eht no reeb fo 

External Resources

Implementation (Crystal)

Slow, ugly browser implementation (Crystal)

Alternate implementation (Crystal)