1
0

Add questions 1-3

This commit is contained in:
2023-09-28 16:13:48 -04:00
parent d4cf6b25c8
commit 6bee470b8a
4 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
{-
https://projecteuler.net/problem=1
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.
-}
module Main where
main :: IO ()
main = print ans
ans :: Integer
ans = sum $ allNumbersUnder 1000
isMultipleOf :: Integral a => a -> a -> Bool
isMultipleOf n x = x `rem` n == 0
all3sUnder :: Integral a => a -> [a]
all3sUnder n = filter (isMultipleOf 3) [1..n-1]
all5sUnder :: Integral a => a -> [a]
all5sUnder n = filter (isMultipleOf 5) [1..n-1]
allXsUnderN :: Integral a => a -> a -> [a]
allXsUnderN x n = filter (isMultipleOf x) [1..n-1]
allNumbersUnder :: Integral a => a -> [a]
allNumbersUnder l = allXsUnderN 3 l <> allXsUnderN 5 l