Skip to content

Instantly share code, notes, and snippets.

@fnoble
Last active March 22, 2016 01:13
Show Gist options
  • Save fnoble/866395fcac363208a1a0 to your computer and use it in GitHub Desktop.
Save fnoble/866395fcac363208a1a0 to your computer and use it in GitHub Desktop.
Euler 5 Haskell Golf
-- 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