Skip to content

Instantly share code, notes, and snippets.

@danielcristofani
danielcristofani / tictactoe.b
Last active December 3, 2020 13:50
Tic-tac-toe player
--->--->>>>->->->>>>>-->>>>>>>>>>>>>>>>>>+>>++++++++++[ initialization
<<++[ output board
--<+<<+<<+>>>>[
>[<->>+++>>[-]<<<+[<++>>+>>-<<<--]]+>+++++[>>++++++++++<<-]
>>-.[-]>>+[<<<<+>>+>>-]<<<<<<[>+<-]<<
]++++++++++.[-]>++
]-->>[-->[-]>]<<[ if game not over
>>--[ while stack isn't empty
-[
-[ fn 0: get move from user
@danielcristofani
danielcristofani / sort.rui
Created August 9, 2020 02:39
Sort bytes in ascending order
=256 R +4 . +1
:2
=2 . . . =0 . .
-256 *5 !
-0 +7 . . +6 . . . *5 !
-0 W *3 !
-0 *8 !
-0 +9 . . *3 :5
-256 =1 +3 ~
@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
@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 / 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 / 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
w *2 =1 :1
=1 $
@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
@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 / 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 !