Fractran: Difference between revisions

m
no edit summary
mNo edit summary
Line 1,864:
exec(2);
</lang>
 
=={{header|Julia}}==
<lang julia>
function fractran(n, rationals, steplimit)
ret = zeros(BigInt, steplimit)
for i in 1:steplimit
ret[i] = n
if (pos = findfirst(r -> isinteger(n*r), rationals)) > 0
n *= rationals[pos]
else
break
end
end
ret
end
 
function str2Rationals(s)
a = collect(split(s,r"[\s,/]+"))
[parse(BigInt,a[i])//parse(BigInt,a[i+1]) for i in 1:2:length(a)-1]
end
fracstring = """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"""
fracts = str2Rationals(fracstring)
println("The first 20 in the series are ", fractran(2, fracts, 20))
 
primesfound = 0
n = BigInt(2)
while primesfound < 20
if isinteger(log2(n))
primesfound += 1
println("Prime $primesfound found: $n is 2 ^ $(Int(round(log2(n))))")
end
n = fractran(n, fracts, 2)[2]
end
</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]
Prime 1 found: 2 is 2 ^ 1
Prime 2 found: 4 is 2 ^ 2
Prime 3 found: 8 is 2 ^ 3
Prime 4 found: 32 is 2 ^ 5
Prime 5 found: 128 is 2 ^ 7
Prime 6 found: 2048 is 2 ^ 11
Prime 7 found: 8192 is 2 ^ 13
Prime 8 found: 131072 is 2 ^ 17
Prime 9 found: 524288 is 2 ^ 19
Prime 10 found: 8388608 is 2 ^ 23
Prime 11 found: 536870912 is 2 ^ 29
Prime 12 found: 2147483648 is 2 ^ 31
Prime 13 found: 137438953472 is 2 ^ 37
Prime 14 found: 2199023255552 is 2 ^ 41
Prime 15 found: 8796093022208 is 2 ^ 43
Prime 16 found: 140737488355328 is 2 ^ 47
Prime 17 found: 9007199254740992 is 2 ^ 53
Prime 18 found: 576460752303423488 is 2 ^ 59
Prime 19 found: 2305843009213693952 is 2 ^ 61
Prime 20 found: 147573952589676412928 is 2 ^ 67
</pre>
 
=={{header|Kotlin}}==
4,108

edits