``` 08b6f9aa » Eric Wilson ``` 2011-01-12 refactored 3 and 12 for speed and readability 1 import EulerMath.Primes 2 import EulerMath.Divisors ``` 92284cad » Eric Wilson ``` 2011-01-04 Problems 1-6,8-9 3 ``` 08b6f9aa » Eric Wilson ``` 2011-01-12 refactored 3 and 12 for speed and readability 4 firstPrimeFactor :: Integer -> Integer 5 firstPrimeFactor n = head [ d | d <- primesUpTo n, mod n d == 0] ``` 92284cad » Eric Wilson ``` 2011-01-04 Problems 1-6,8-9 6 ``` 08b6f9aa » Eric Wilson ``` 2011-01-12 refactored 3 and 12 for speed and readability 7 reduceByNextPrime :: Integer -> Integer 8 reduceByNextPrime n = reduce n (firstPrimeFactor n) ``` 92284cad » Eric Wilson ``` 2011-01-04 Problems 1-6,8-9 9 where reduce num div = 10 if mod num div /= 0 11 then num 12 else reduce (quot num div) div ``` 08b6f9aa » Eric Wilson ``` 2011-01-12 refactored 3 and 12 for speed and readability 13 ``` 92284cad » Eric Wilson ``` 2011-01-04 Problems 1-6,8-9 14 euler3 :: Integer -> Integer ``` 08b6f9aa » Eric Wilson ``` 2011-01-12 refactored 3 and 12 for speed and readability 15 euler3 n = 16 if reduced == 1 17 then n 18 else euler3' reduced 19 where reduced = reduceByNextPrime n