# Generating primes in the old fashioned way # Test if a number is a prime by examining the residue of division # by all numbers less than or equal to the square root of the number. # If no residue is 0 the number is a prime. isp is operation X { (X > 1) and (and (0 < (X eachright mod (2 drop tell (1 + floor sqrt X))))) } # Find all primes up to the supplied number by testing each to see if it # is a prime and then selecting the sublist of numbers that are primes. isp_list is op N { r := each isp (count N); r sublist (count N) } # Find the primes up to 1000. If you want to run this interactively # then remove the 'bye' line and use # # Nial -i # loaddefs "primes write ('Primes to 1000' (isp_list 1000)); # That's all folks bye;