# Primes by Trial Division - APL

13 August 2016

Since my IBM 5100 has both BASIC and APL, I thought I'd try an APL version of the benchmark. It should be considered an idomatic—rather than a strict—port, as it is expressed in such a way as to perform the modulus function on the entire vector of identified primes. In the BASIC versions, the divisions are performed one at a time and the inner loop is terminated early at the first prime the candidate is evenly divisble by.

∇ FOUND←PRIMES N;FOUND;COUNT [1] FOUND←1⍴2 [2] COUNT←3 [3] START:→(N=⍴FOUND)/0 [4] →(0∈FOUND|COUNT)/NEXT [5] FOUND←FOUND,COUNT [6] NEXT:COUNT←COUNT+1 [7] →START ∇