changeset 92:6f650dd96685

Minor tweak to prime efficiency
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Jun 2019 20:50:43 +0100
parents 075ff4e4feaf
children 39084e2b8744
files 7-Haskell/day2.hs
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/7-Haskell/day2.hs	Mon Jun 17 20:26:30 2019 +0100
+++ b/7-Haskell/day2.hs	Mon Jun 17 20:50:43 2019 +0100
@@ -54,4 +54,5 @@
     
     -- Wilson's theorem seems easiest: https://en.wikipedia.org/wiki/Wilson%27s_theorem
     primes :: [Integer]
-    primes = [x | x <- [2 ..], (mod ((product [1 .. x-1]) + 1) x) == 0]
\ No newline at end of file
+    -- Primes after 2 have to be odd (or else they're a multiple of 2!), so increment up the odd numbers
+    primes = 2 : [x | x <- [3, 5 ..], (mod ((product [1 .. x-1]) + 1) x) == 0]
\ No newline at end of file