Created
September 18, 2013 18:18
-
-
Save bryanwoods/6613213 to your computer and use it in GitHub Desktop.
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
-- 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. -- | |
allNums :: Int -> [Int] | |
allNums max = [1..max] | |
divisible :: Int -> Int -> Bool | |
divisible x y = y `mod` x == 0 | |
divisible2 :: Int -> Int -> Int -> Bool | |
divisible2 x y = (\n -> (divisible x n) || (divisible y n)) | |
printInt :: Int -> IO () | |
printInt x = putStrLn $ show x | |
solution :: Int -> Int -> Int -> Int | |
solution x y max = sum $ filter (divisible2 x y) (allNums max) | |
main = printInt $ solution 3 5 999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wondering (especially compared to my 1 one Ruby solution) if I'm going overboard with trying to make "tiny, simple" functions, and if there are any tricks I might not know yet that are making this code read as obviously noobish.