Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pass 2, about 30% better (on my machine) than my previous. The main saving came from unrolling the inner loop to amortize the overhead.</p> <p>Also included (commented out) is an aborted attempt to save time by exiting early (&amp; set the pixel black) when you are stuck in the central cardioid. It works, but it's slower no matter how I jiggered it.</p> <p>I've got to run, but I'll leave a parting suggestion. There may be some optimization possible by run-length encoding the results (so instead of saving a bunch of bit-twiddled chars you'd save a list (number of white dots, number of black dots, number of white dots, etc.)). This would:</p> <ol> <li>Reduce the storage/GC overhead </li> <li>Allow some optimizations on the output generation (when the numbers were >> 8)</li> <li>Permit some orbit detection.</li> </ol> <p>No idea if it could be coded tight enough to fly, but that is where I would try next if I had more time.</p> <pre><code>-- The Computer Language Shootout -- http://shootout.alioth.debian.org/ -- contributed by Mike Pall -- with optimizations by Markus J. Q. (MarkusQ) Roberts local width = tonumber(arg and arg[1]) or 100 local height, wscale = width, 2/width local m, limit2 = 50, 4.0 local write, char = io.write, string.char local h2 = math.floor(height/2) local hm = height - h2*2 local top_half = {} for y=0,h2+hm do local Ci = 2*y / height - 1 local line = {""} for xb=0,width-1,8 do local bits = 0 local xbb = xb+7 for x=xb,xbb &lt; width and xbb or width-1 do bits = bits + bits local Zr, Zi, Zrq, Ziq = 0.0, 0.0, 0.0, 0.0 local Cr = x * wscale - 1.5 local Zri = Zr*Zi for i=1,m/5 do Zr = Zrq - Ziq + Cr Zi = Zri + Zri + Ci Zri = Zr*Zi Zr = Zr*Zr - Zi*Zi + Cr Zi = 2*Zri + Ci Zri = Zr*Zi Zr = Zr*Zr - Zi*Zi + Cr Zi = 2*Zri + Ci Zri = Zr*Zi Zr = Zr*Zr - Zi*Zi + Cr Zi = 2*Zri + Ci Zri = Zr*Zi Zr = Zr*Zr - Zi*Zi + Cr Zi = 2*Zri + Ci Zri = Zr*Zi Zrq = Zr*Zr Ziq = Zi*Zi Zri = Zr*Zi if Zrq + Ziq &gt; limit2 then bits = bits + 1 break end -- if i == 1 then -- local ar,ai = 1-4*Zr,-4*Zi -- local a_r = math.sqrt(ar*ar+ai*ai) -- local k = math.sqrt(2)/2 -- local br,bi2 = math.sqrt(a_r+ar)*k,(a_r-ar)/2 -- if (br+1)*(br+1) + bi2 &lt; 1 then -- break -- end -- end end end for x=width,xbb do bits = bits + bits + 1 end table.insert(line,char(255-bits)) end line = table.concat(line) table.insert(top_half,line) end write("P4\n", width, " ", height, "\n") for y=1,h2+hm do write(top_half[y]) end for y=h2,1,-1 do write(top_half[y]) end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload