From e923c84095c01903eeb16f2166733dd0fe407f5a Mon Sep 17 00:00:00 2001 From: Boris Skert Date: Sat, 28 Sep 2024 18:54:16 +0200 Subject: [PATCH] Solve 'Sum the nums, sum the sums and sum the nums up to that sum' kata --- src/NumTheNums.hs | 6 ++++++ test/NumTheNumsSpec.hs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/NumTheNums.hs create mode 100644 test/NumTheNumsSpec.hs diff --git a/src/NumTheNums.hs b/src/NumTheNums.hs new file mode 100644 index 0000000..638e85a --- /dev/null +++ b/src/NumTheNums.hs @@ -0,0 +1,6 @@ +module NumTheNums (sumOfSums) where + +-- https://www.codewars.com/kata/60d2325592157c0019ee78ed/train/haskell + +sumOfSums :: Integer -> Integer +sumOfSums n = n * (n ^ 5 + 6 * n ^ 4 + 13 * n ^ 3 + 18 * n ^ 2 + 22 * n + 12) `div` 72 diff --git a/test/NumTheNumsSpec.hs b/test/NumTheNumsSpec.hs new file mode 100644 index 0000000..91459aa --- /dev/null +++ b/test/NumTheNumsSpec.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE NumericUnderscores #-} + +module NumTheNumsSpec (spec) where + +import NumTheNums (sumOfSums) +import Test.HUnit (assertEqual) +import Test.Hspec + +spec :: Spec +spec = do + it "example tests" $ do + assertEqual "sumOfSums 3" 55 $ sumOfSums 3 + assertEqual "sumOfSums 5" 630 $ sumOfSums 5 + assertEqual "sumOfSums 100" 14_740_530_850 $ sumOfSums 100