-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solve 'Sum the nums, sum the sums and sum the nums up to that sum' kata
- Loading branch information
1 parent
ad473cc
commit e923c84
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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 |