Fractran: Difference between revisions

52 bytes added ,  11 months ago
m
Line 2,718:
 
using .Iterators: filter, map, take
import Base: iterate, show
 
struct Fractran
rs::Vector{Rational{BigInt}}
i₀::BigInt
limit::Int
end
 
Base.iterate(f::Fractran, i = f.i₀) =
for r in f.rs
if iszero(i % r.den)
Line 2,733:
end
 
runinterpret(f::Fractran) = map(trailing_zeros, filter(ispow2, f))
take(
map(trailing_zeros,
filter(ispow2, f))
f.limit)
 
Base.show(io::IO, f::Fractran) = join(io, take(run(f), 30), ' ')
join(io, interpret(f), ' ')
 
macro code_str(s)
[eval(Meta.parse("[" * replace(st, "/" => "//"))) *for "t ∈ split(s)]"))
end
 
primes = Fractran(code"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", 2, 30)
 
# Output
39

edits