Created
November 4, 2012 20:46
-
-
Save jnape/4013713 to your computer and use it in GitHub Desktop.
Solution to Project Euler #1 in Haskell
This file contains 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
module Euler1 where | |
{- | |
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
Find the sum of all the multiples of 3 or 5 below 1000. | |
-} | |
import Data.List (nub) | |
multiplesOf :: Int -> [Int] -> [Int] | |
multiplesOf n [] = [] | |
multiplesOf n xs = [x | x <- xs, x % n] | |
(%) :: Int -> Int -> Bool | |
a % b = rem a b == 0 | |
main :: IO () | |
main = print $ | |
let range = [1..999] | |
in sum $ nub $ multiplesOf 3 range ++ multiplesOf 5 range |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment