Skip to content

Instantly share code, notes, and snippets.

@danielcristofani
danielcristofani / mrm_rui.c
Last active July 1, 2020 11:13
This program translates Minsky register machine programs to Rui programs.
/* mrm_rui.c -- translate Minsky register machine to Rui
Daniel Cristofani
6/2020 */
/* This program translates register machine programs, as described in Marvin
Minsky's 1967 book _Computation: Finite and Infinite Machines_, into Rui
programs as described at https://esolangs.org/wiki/Rui, thus proving Rui
to be Turing-complete.
Minsky's book gives several varieties of register machine. This program
+6 +7 +9
+8 -7 *11 -9 *12 -8 $ *8 . -6 *7 *6
=0 +4 -7 *7 . . . . *13 -7 +10 :3
-9 *9 ~ . . -0 =7 . -6 *6 *7 +5 -7 *7 . . . . -0 +14 -7 . *7 :2
-9 *9 ~ . . -0 . +14 -7 . *7 . -10 w -7 *11 -6 *15 =10 $ :3
=6:6
=7:7
=8:8
=9:9
=10:10
@danielcristofani
danielcristofani / sqrt.rui
Created July 18, 2020 02:42
Compute square roots. (Slow for large numbers.)
r *7
=0 +3 . -7 *7 . . . . . . *4 -1 -7 +9 +8 +8 :2
-8 . *8 ~ . . -0 =1 ~ . . -9 w +10 -7 . *5 -8 *6 :2
. :7
=100 *7 !
=10 *8 !
=7:7
=8:8
=9:9
. -0 *11 !
@danielcristofani
danielcristofani / factorial.rui
Created July 18, 2020 02:44
Compute factorial
r +5 +4 .
. *3 -1 -4 $ *4 +5 -2 :2
. . . *4 =2 .
=4 :4
=1 ~ -0 =1 . -4 w
@danielcristofani
danielcristofani / drui.c
Last active July 26, 2020 04:23
Rui interpreter
/* drui.c -- Rui interpreter
Daniel Cristofani
7/2020 */
/* A reasonably fast interpreter for the Rui programming language, as described at https://esolangs.org/wiki/Rui
This uses the GMP bignum library, so it will need to be compiled with something like
gcc drui.c -O2 -o drui -lgmp
w *2 =1 :1
=1 $
@danielcristofani
danielcristofani / collatz.rui
Created July 20, 2020 02:18
Outputs Collatz sequence for one input
r
w +5 . *4 +3 $ . . -0 . -6 :2
. . -0 . -0 =4 *3 -0 :2
. . -0 . . =6 . *3 !
-1 -0
@danielcristofani
danielcristofani / collatz2.rui
Created July 20, 2020 02:20
Compute lengths of Collatz sequences for successive numbers
+2 . *6 +3 . . . -0 . -6 +5 :1
-1 -0 =1 . -5 +4 w -4 *4 :1
-1 . -0 . -0 =4 *6 -0 +5 :1
=4 :4
=5 :5
. =2 -0 . . =6 . *6
@danielcristofani
danielcristofani / sierpinski.rui
Last active July 22, 2020 04:50
Output Sierpiński triangle
-3 *2 -7 *7 *7 -5 +10. *4 -4 . -0 +6 . *8 $ -2 . :1
=9 *3
=3 :3
=1 -0 .
=5 :5
-8 . . . *3 *7 !
=7 :7
=8 :8
=9 :9
-0 =4 . +9 +3 +7 -3 w -9 +11. *9 -7 *5 :1
@danielcristofani
danielcristofani / pi.rui
Last active August 10, 2020 09:55
Compute pi by Bailey-Borwein-Plouffe formula
+7 +4 +3 :10
=2:2
=3:3
=4:4
=5:5
=6:6
=7:7
=8:8
=9:9
-8 =120 +12 *11 . =151 *11 . =47 *11 -3 $ *3 -7 $ *7 . -0 *8 :13