Skip to content

Commit

Permalink
Solve 'Sum the nums, sum the sums and sum the nums up to that sum' kata
Browse files Browse the repository at this point in the history
  • Loading branch information
borisskert committed Sep 28, 2024
1 parent ad473cc commit e923c84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/NumTheNums.hs
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions test/NumTheNumsSpec.hs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e923c84

Please sign in to comment.