From e729d214d798032ccba0240a07466b7a9a75c5ba Mon Sep 17 00:00:00 2001 From: Dustin Sallings Date: Mon, 16 Mar 2009 22:05:27 -0700 Subject: [PATCH] Euler 6. --- haskell/euler/6.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 haskell/euler/6.hs diff --git a/haskell/euler/6.hs b/haskell/euler/6.hs new file mode 100644 index 000000000..ab6f289b4 --- /dev/null +++ b/haskell/euler/6.hs @@ -0,0 +1,23 @@ +-- The sum of the squares of the first ten natural numbers is, +-- 1^(2) + 2^(2) + ... + 10^(2) = 385 + +-- The square of the sum of the first ten natural numbers is, +-- (1 + 2 + ... + 10)^(2) = 55^(2) = 3025 + +-- Hence the difference between the sum of the squares of the first +-- ten natural numbers and the square of the sum is 3025 − 385 = 2640. + +-- Find the difference between the sum of the squares of the first one +-- hundred natural numbers and the square of the sum. + +sum_of_squares :: [Integer] -> Integer + +sum_of_squares l = sum [ n * n | n <- l ] + +square_of_sums :: [Integer] -> Integer + +square_of_sums l = (sum l) ^ 2 + +euler_6 :: [Integer] -> Integer + +euler_6 l = square_of_sums l - sum_of_squares l \ No newline at end of file