From 51ae128a149af9ec614e1c5513a858981e2fb225 Mon Sep 17 00:00:00 2001 From: Bill Ewanick Date: Fri, 15 Mar 2024 00:03:31 -0400 Subject: [PATCH] Go back to a `sum` in prelude --- src/projectEuler/question1.hs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/projectEuler/question1.hs b/src/projectEuler/question1.hs index 64d4715..eca7daa 100644 --- a/src/projectEuler/question1.hs +++ b/src/projectEuler/question1.hs @@ -5,9 +5,6 @@ The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. -} -{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} -{-# HLINT ignore "Use sum" #-} - module Main where import Data.List (union) @@ -16,26 +13,13 @@ main :: IO () main = print ans ans :: Integer -ans = sum $ allNumbersUnder 1000 - -sum' :: Num a => [a] -> a -sum' = foldl (+) 0 - -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 - +ans = sum (_3s <> _5s) +_3s :: [Integer] _3s = [3,6..999] + +_5s :: [Integer] _5s = [5,10..999] + +solution :: Integer solution = sum $ union _3s _5s