Problem #10:

∇R←PETEN;D;I;N;X;⎕IO ⎕IO←1⍝ Find the Sum of all the primes below two million.

N←2000000 ⋄ I←2 ⋄ X←N⍴1 ⋄ D←10000

LOOP:X[I×1↓⍳⌊N÷I]←0 ⋄ I←I+(I↓X)⍳1 ⋄ →((I*2)≤N)/LOOP

X←+/(2⍴D)⊤X/⍳NI←(⍴X[1])-4 ⋄ R←(X[1]+⌊X[2]÷D)(D|X[2])

∇

This was a bit of a fun one, since I had trouble trying to get the result into a 32-bit integer. I had to do a bit of math to get that to work. This one I did a while back, actually, so I am not sure that it contains all of the wisdom that I have learned from the previous feedback!

Problem #10:

Problem #10:

∇R←PETEN;D;I;N;X;⎕IO ⎕IO←1⍝ Find the Sum of all the primes below two million.

N←2000000 ⋄ I←2 ⋄ X←N⍴1 ⋄ D←10000

LOOP:X[I×1↓⍳⌊N÷I]←0 ⋄ I←I+(I↓X)⍳1 ⋄ →((I*2)≤N)/LOOP

X←+/(2⍴D)⊤X/⍳NI←(⍴X[1])-4 ⋄ R←(X[1]+⌊X[2]÷D)(D|X[2])

∇