Project Euler
Problem 1
1 one :: Int -> Int
2 one n = sum [x | x <- [1..n], (mod x 3 == 0 || mod x 5 == 0)]
3
4 main = print $ one 999
Problem 4
1 four = maximum [x | x1<-[100..999], x2<-[100..999], let x=x1*x2, let p=show x, p==reverse p]
2 main = print $ four
Problem 7
1 primes = 2 : f [3] [3,5..]
2 where f(x:xs) ys = let (ps, qs) = span (< x^2) ys
3 in ps ++ f (xs ++ ps) [z | z <- qs, mod z x /= 0]
4 main = print $ primes !! 10000
Problem 10
1 ten :: Int -> Int
2 ten n = sum primes2
3 where primes = 2:f [3] [3,5..] where f (x:xs) ys = let (ps, qs) = span (< x^2) ys
4 in ps ++ f (xs ++ ps) [z | z <- qs, mod z x /= 0]
5 primes2 = takeWhile (<n) primes
6
7 main = print $ ten 2000000
alstamber/ProjectEuler (last edited 2012-12-22 13:49:58 by alstamber)