reset password
Author Message
rabbott
Posts: 1649
Posted 20:24 Aug 24, 2016 |

In class we talked about using primes to look for divisors of a possible prime. The code might look like this,

oddsFrom3 = [3, 5 .. ]
primeDivisors n = [d | d <- takeWhile (<= n `div` 2) primes, n `mod` d == 0]
primes = 2 : [p | p <- oddsFrom3, null (primeDivisors p) ] 

 

The concern was that since primes uses primeDivisors one can't refer to primes inside primeDivisors. But since the primes used by primeDivisors are all smaller that the current possible prime, that turns out not to be a problem.