Fractran: Difference between revisions

Content added Content deleted
mNo edit summary
Line 1,866:
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang julia>
<lang julia>function fractran(n::Integer, rationalsratios::Vector{<:Rational}, steplimitsteplim::Integer)
retrst = zeros(BigInt, steplimitsteplim)
for i in 1:steplimitsteplim
retrst[i] = n
if (pos = findfirst(rx -> isinteger(n *r x), rationalsratios)) > 0
n *= rationalsratios[pos]
else
break
end
end
retreturn rst
end
 
using IterTools
function str2Rationals(s)
macro ratio_str(s)
a = collect(split(s, r"[\s,/]+"))
[return collect(parse(BigInt,a[i] n) // parse(BigInt,a[i+1] d) for i(n, d) in 1:2:lengthpartition(a, 2))-1]
end
 
fracstringfracs = ratio"""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"""
println("The first 20 in the series are ", fractran(2, fractsfracs, 20))
fracts = str2Rationals(fracstring)
println("The first 20 in the series are ", fractran(2, fracts, 20))
 
primesfoundprmfound = 0
n = BigIntbig(2)
while primesfoundprmfound < 20
if isinteger(log2(n))
primesfoundprmfound += 1
println("Prime $primesfoundprmfound found: $n is 2 ^ $(Int(round(log2(n))))")
end
n = fractran(n, fractsfracs, 2)[2]
end</lang>
 
</lang>
{{output}}
<pre>The first 20 in the series are BigInt[2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132, 116, 308, 364, 68, 4]
<pre>
The first 20 in the series are BigInt[2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132, 116, 308, 364, 68, 4]
Prime 1 found: 2 is 2 ^ 1
Prime 2 found: 4 is 2 ^ 2
Line 1,923 ⟶ 1,921:
Prime 18 found: 576460752303423488 is 2 ^ 59
Prime 19 found: 2305843009213693952 is 2 ^ 61
Prime 20 found: 147573952589676412928 is 2 ^ 67</pre>
</pre>
 
=={{header|Kotlin}}==