Fractran: Difference between revisions
Content added Content deleted
Line 2,554: | Line 2,554: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{works with|Julia|1. |
{{works with|Julia|1.9}}<syntaxhighlight lang="julia"> |
||
⚫ | |||
struct Fractran |
|||
input::BigInt |
|||
fracs::Vector{Rational{BigInt}} |
|||
n::Int |
|||
end |
|||
function Base.iterate(ft::Fractran, i = ft.input) |
function Base.iterate(ft::Fractran, i = ft.input) |
||
Line 2,563: | Line 2,570: | ||
end |
end |
||
eval(ft::Fractran |
function eval(ft::Fractran) |
||
(Int(log2(i)) for i ∈ ft if ispow2(i)) |
|||
end |
|||
Base.show(io::IO, ft::Fractran |
function Base.show(io::IO, ft::Fractran) |
||
⚫ | |||
end |
|||
macro code_str(s) |
macro code_str(s) |
||
eval(Meta.parse("[" * replace(s, "/" => "//", " |
eval(Meta.parse("[" * replace(s, "/" => "//", " " => ",") * "]")) |
||
end |
end |
||
primes = Fractran(2, |
primes = Fractran(2, |
||
code"17/91 |
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", |
||
25) |
|||
95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1") |
|||
⚫ | |||
println("FRACTRAN interpreter implemented in Julia as an iterable struct\n") |
|||
join(Iterators.take(primes, 30), ' '), "\n") |
|||
⚫ | |||
⚫ | |||
⚫ | |||
println("First $(primes.n) primes:") |
|||
⚫ | |||
{{output}} |
{{output}} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
First 25 primes: |
|||
primes = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |