Re: Can OpenEuphoria Help Solve This?
- Posted by petelomax Aug 21, 2018
- 1775 views
The Phix algorithm from Rosetta Code:
From Lua Rosetta Code:
n = 1000
The test method:
system( "p p_pi.ex" ) ? time() - t
Phix is three time faster than LuaJIT.
Firstly, system() returns before the command is complete, you must use {} = system_exec() instead.
Secondly, that horrible golf entry calculates 2400 places, so you'd need to change the n in the lua entry to 2400.
I now have a working luajit here, and found that Phix was a full 16 times faster!
However, it is a completely different algorithm, calculating 4 digits per iteration for one thing, so here is the lua one translated to phix (and upped to 2400 dp, and sneakily optimised a bit):
integer n = 2400, len = floor(10*n/3) sequence a = repeat(2,len) integer nines = 0, predigit = 0 string res = "" for j=1 to n do integer q = 0 for i=len to 1 by -1 do integer x = 10*a[i]+q*i, d = 2*i-1 a[i] = remainder(x,d) q = floor(x/d) end for a[1] = remainder(q,10) q = floor(q/10) if q==9 then nines = nines+1 else integer nine = '9' if q==10 then predigit += 1 q = 0 nine = '0' end if res &= predigit+'0'&repeat(nine,nines) predigit = q nines = 0 end if end for res &= predigit+'0' puts(1,res)
Now, slightly fairer, I'm seeing Phix being 2.35 times faster than Lua - to be honest that quite surprises me.
Pete
PS: lua (and LOVE) are really quite good, and definitely have some advantages, but they simply don't quite get me further enough along. If only LOVE had IUP working on android, or lua.js was not 50MB...