Re: Pi Benchmark Game
- Posted by Pirx Aug 23, 2018
- 1750 views
OK. Please, run this code. It calculates 10000 digits of PI.
Euphoria:
include std/math.e include std/text.e atom n = 35001, a = 10000, d, g, k, e = 0 sequence f = repeat(2000, n) for c = n to 14 by -14 do d = 0 for b = c to 1 by -1 do d = d * b g = b * 2 - 1 d = d + f[b] * a f[b] = mod(d, g) d = floor(d / g) k = e + floor(d / a) end for sequence k2 = "000000" & sprint(k) puts(1, k2[(length(k2) - 3)..(length(k2))]) e = mod(d, a) end for
Lua:
n, a, d, g, k, e = 35001, 10000, 0, 0, 0, 0 f = {} for x = 1, n do f[x] = 2000 end for c = n, 14, -14 do d = 0 for b = c, 1, -1 do d = d * b g = b * 2 - 1 d = d + f[b] * a f[b] = d % g d = math.floor(d / g) k = e + math.floor(d / a) end k2 = "000000" .. tostring(k) io.write(string.sub(k2, string.len(k2) - 3)) e = d % a end
As you can see, it's the same algorithm. On my machine Luajit takes 0m0.941s (less than one second) to calculate and print 10000 digits of PI, while interpreted Euphoria takes 24 sec.