Euler problems/11 to 20: Difference between revisions
(→[http://projecteuler.net/index.php?section=problems&id=12 Problem 12]: add a solution) |
(problem_20) |
||
Line 83: | Line 83: | ||
Solution: | Solution: | ||
<haskell> | <haskell> | ||
problem_20 = | problem_20 = let fac n = product [1..n] in | ||
foldr ((+) . Data.Char.digitToInt) 0 $ show $ fac 100 | |||
</haskell> | </haskell> | ||
Revision as of 03:53, 28 March 2007
Problem 11
What is the greatest product of four numbers on the same straight line in the 20 by 20 grid?
Solution:
problem_11 = undefined
Problem 12
What is the first triangle number to have over five-hundred divisors?
Solution:
problem_12 = head $ filter ((> 500) . nDivisors) triangleNumbers
where triangleNumbers = scanl1 (+) [1..]
nDivisors n = product $ map ((+1) . length) (group (primeFactors n))
primes = 2 : filter ((== 1) . length . primeFactors) [3,5..]
primeFactors n = factor n primes
where factor n (p:ps) | p*p > n = [n]
| n `mod` p == 0 = p : factor (n `div` p) (p:ps)
| otherwise = factor n ps
Problem 13
Find the first ten digits of the sum of one-hundred 50-digit numbers.
Solution:
problem_13 = undefined
Problem 14
Find the longest sequence using a starting number under one million.
Solution:
problem_14 = undefined
Problem 15
Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
Solution:
problem_15 = undefined
Problem 16
What is the sum of the digits of the number 21000?
Solution:
problem_16 = undefined
Problem 17
How many letters would be needed to write all the numbers in words from 1 to 1000?
Solution:
problem_17 = undefined
Problem 18
Find the maximum sum travelling from the top of the triangle to the base.
Solution:
problem_18 = undefined
Problem 19
How many Sundays fell on the first of the month during the twentieth century?
Solution:
problem_19 = undefined
Problem 20
Find the sum of digits in 100!
Solution:
problem_20 = let fac n = product [1..n] in
foldr ((+) . Data.Char.digitToInt) 0 $ show $ fac 100