prime.hs 361 B

12345678910111213
  1. -- Exercice from slide 42
  2. dividers n = [k | k <- takeWhile (\k -> k * k <= n) primeinf, rem n k == 0]
  3. dividersf n = filter (\k -> rem n k == 0) [2..(n-1)]
  4. primer n = [i | i <- [2..(n-1)], null (dividers i)]
  5. primerf n = filter (\i -> null (dividersf i)) [2..(n-1)]
  6. square n = n * n
  7. -- Exercice from slide 50
  8. primeinf = 2:[i | i <- [3..], null (dividers i)]