esolangs/fractran.bqn

36 lines
888 B
BQN
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Fractran interpreter
# Helpers
_while_ {𝔽𝔾𝔽_𝕣_𝔾𝔽𝔾𝕩}
ToInt 10×+˜´·-'0'
ToFrac {
i /'/'=𝕩
ToInt¨i(1+)𝕩
}
Split ((¬-˜×·+`»>))
Fractran {
𝕊 nnumden:
ind /0=den|num×n
(n×indnum)÷indden num den
}
RunFractran {
steps 𝕊 inpprg:
numden <˘>ToFrac¨' 'Split prg
step 1
list inp
{
step + 1
out Fractran 𝕩
list out
out
} _while_ {𝕊 nnumden: (step<steps) ´0=den|num} inpnumden
list
}
seq 200 RunFractran 2"17/91 78/85 19/51 23/38 29/33 77/29 95/23 77/19 1/17 11/13 13/11 15/14 15/2 55/1"
•Out "Generated numbers: "•Repr seq
•Out "Primes: "•Repr 12(=)(2())/ seq