esolang

Rui

Each thread holds one number. To add two numbers you spawn a thread for every unit and kill them all to count them.

Sinthorion, 2020 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 7

The idea

Sinthorion made Rui in 2020 and named it after Rui from Kimetsu no Yaiba. A thread has one non-negative number and a place in the code, and that is all the memory there is. No thread can add to its own number, and there is no conditional jump. Everything is done by threads that spawn, kill and change each other.

Read the story

Time is part of every program. In each cycle every thread runs one instruction, the oldest first, and a thread spawned in a cycle waits for the next one. A . makes a thread wait one cycle, and the specification says precise timing is critical. Daniel Cristofani proved Rui Turing complete by translating Minsky machines into it.

The machine

InstructionDoes
=5Set the thread's number to 5
+2Spawn a thread at line 2, with the number 0
*2Spawn as many threads at line 2 as the thread's number
-5Kill every other thread whose number is 5, and take the count of them
$ ~Add the number to every other thread, or take it away down to 0
:2Jump to line 2
r wRead a number, write the number
. !Wait a cycle; end the thread

A thread runs on into the next line and dies past the last one. The program ends when no thread is left. This is strict Rui, so input is known from the start and reads as 0 once it is used up.

Example

The first thread reads 3 and spawns 3 threads that loop on line 2 with the number 0.

The first thread reads 3 and spawns 3 threads that loop on line 2 with the number 0. It reads 4 and spawns 4 more. Then -0 kills all 7 and leaves the count, 7, in the first thread, which writes it.

The +2=1. over ..w+2$ writes every Fibonacci number and never stops. Two threads start with 0 and 1. Each waits, writes its number, spawns the next thread and adds its number to all the others before it dies. It writes 0, 1, 1, 2, 3, 5, 8 and on until the run reaches its step limit.

Patterns it teaches

Further

Concurrent programming

Write your own in Run Convert a program from Rui

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: rui.

Command line

shib run rui -e 'r*2r*2-0w!
:2' --input '3 4'
shib manual rui

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/rui.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org