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
euler6 :: Int | |
euler6 = a - b | |
where | |
a = (^2) $ sum [1..100] | |
b = sum [x^2 | x <- [1..100]] |
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
leastDivisor :: Integer -> Integer -> Integer | |
leastDivisor divisor n | |
| rem n divisor == 0 = divisor | |
| divisor^2 > n = n | |
| otherwise = leastDivisor (divisor+1) n | |
hasFactor :: Integer -> Bool | |
hasFactor 1 = False | |
hasFactor n = (leastDivisor 2 n) /= n |
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
import Data.Char (digitToInt) | |
import Data.List (tails) | |
euler8 :: Int | |
euler8 = maximum $ map (product . take 5) (tails number) | |
where | |
str = "73167176531330624919225119674426574742355349194934\ | |
\96983520312774506326239578318016984801869478851843\ | |
\85861560789112949495459501737958331952853208805511\ | |
\12540698747158523863050715693290963295227443043557\ |
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
euler9 :: Int | |
euler9 = floor $ head [a * b * c | b <- [1..998], a <- [1..b], let c2 = a^2 + b^2, let c = sqrt c2, a + b + c == 1000, a^2 + b^2 == c2] |
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
leastDivisor :: Integer -> Integer -> Integer | |
leastDivisor divisor n | |
| rem n divisor == 0 = divisor | |
| divisor^2 > n = n | |
| otherwise = leastDivisor (divisor+1) n | |
hasFactor :: Integer -> Bool | |
hasFactor 1 = False | |
hasFactor n = (leastDivisor 2 n) /= n |
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
import Data.List (group) | |
leastDivisor :: Integer -> Integer -> Integer | |
leastDivisor divisor n | |
| rem n divisor == 0 = divisor | |
| divisor^2 > n = n | |
| otherwise = leastDivisor (divisor+1) n | |
factors :: Integer -> [Integer] | |
factors 1 = [] |
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
euler13 :: String | |
euler13 = (take 10) . show . sum $ nums | |
nums :: [Integer] | |
nums = [37107287533902102798797998220837590246510135740250, | |
46376937677490009712648124896970078050417018260538, | |
74324986199524741059474233309513058123726617309629, | |
91942213363574161572522430563301811072406154908250, | |
23067588207539346171171980310421047513778063246676, |
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
import Data.List (foldl') | |
collatz :: Int -> [Int] | |
collatz n | |
| n == 1 = [1] | |
| even n = n : collatz (n `div` 2) | |
| otherwise = n : collatz (3 * n + 1) | |
compareCollatzTuple :: (Int, Int) -> Int -> (Int, Int) | |
compareCollatzTuple acc x = |
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
import Data.Char (digitToInt) | |
euler16 :: Int | |
euler16 = sum $ map digitToInt (show (2^1000)) |
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
import Data.Char (digitToInt) | |
factorial :: (Integral a) => a -> a | |
factorial 0 = 1 | |
factorial n = n * factorial (n - 1) | |
euler20 :: Int | |
euler20 = sum . (map digitToInt) . show . factorial $ 100 |