Fractran: Difference between revisions

81 bytes added ,  11 months ago
m
Line 2,555:
=={{header|Julia}}==
{{works with|Julia|1.9}}<syntaxhighlight lang="julia">
# FRACTRAN interpreter implemented in Julia as an iterable structIterator
 
struct Fractran
input::BigInt
fracs::Vector{Rational{BigInt}}
ninput::IntBigInt
maxout::Int
end
 
Line 2,575 ⟶ 2,574:
 
function Base.show(io::IO, ft::Fractran)
join(io, Iterators.take(eval(ft), ft.nmaxout ), ' ')
end
 
macro code_str(s)
eval(Meta.parse("[" * replace(s, "/" => "//", " " => ",") * "]"))
end
 
# Example FRACTRAN program generating primes
primes = Fractran(2,
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",
77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1", 2, 40)
25)
 
# Output
println("First 25 iterations of FRACTRAN program 'primes':\n2 ",
join(Iterators.take(primes, 3025), ' '), "\n")
 
println("First\nWatch 30the iterationsfirst of$(primes.maxout) FRACTRANprimes programdropping 'primes'out:\n2 ",)
join(Iterators.take(primes, 30), ' '), "\n")
 
println("Watch the first $(primes.n) primes dropping out:")
primes</syntaxhighlight>
{{output}}
<pre>First 3025 iterations of FRACTRAN program 'primes':
2 15 825 725 1925 2275 425 390 330 290 770 910 170 156 132 116 308 364 68 4 30 225 12375 10875 28875 25375 67375 79625 14875 13650 2550
 
Watch the first 2540 primes dropping out:
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> 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173
</pre>
 
=={{header|Kotlin}}==
39

edits