Last active
March 22, 2016 01:13
-
-
Save fnoble/866395fcac363208a1a0 to your computer and use it in GitHub Desktop.
Euler 5 Haskell Golf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Much better | |
foo :: Int -> Int -> Int | |
foo x acc = if acc `mod` x == 0 then acc else lcm acc x | |
mult20 = foldr foo 1 [1..20] | |
-- 1st try | |
primes = [2 :: Integer, 3, 5, 7, 11, 13, 17, 19] | |
isInt x = (x :: Double) == fromInteger (round x) | |
power p x = length $ takeWhile id $ drop 1 $ map isInt $ iterate (/ fromInteger p) $ fromInteger x | |
mult20 = foldr (*) 1 $ zipWith (^) primes $ map maximum $ map (\p -> map (power p) [1..20]) primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment