diff options
| author | Alexander Pankoff <ccntrq@screenri.de> | 2022-11-27 16:32:09 +0100 |
|---|---|---|
| committer | Alexander Pankoff <ccntrq@screenri.de> | 2022-11-27 16:32:09 +0100 |
| commit | 34873fd7fa356aeca06ca2df3a05398eae927356 (patch) | |
| tree | ed924a789452885a58ac426241cee7cdc3ee7057 | |
| parent | 6dcea9af8822db4f23f701909a04c90221b12369 (diff) | |
| download | perlweeklychallenge-club-34873fd7fa356aeca06ca2df3a05398eae927356.tar.gz perlweeklychallenge-club-34873fd7fa356aeca06ca2df3a05398eae927356.tar.bz2 perlweeklychallenge-club-34873fd7fa356aeca06ca2df3a05398eae927356.zip | |
Slightly update haskell solution for ch-192
| -rwxr-xr-x | challenge-192/alexander-pankoff/haskell/ch-2.hs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/challenge-192/alexander-pankoff/haskell/ch-2.hs b/challenge-192/alexander-pankoff/haskell/ch-2.hs index c436550291..c0d023a906 100755 --- a/challenge-192/alexander-pankoff/haskell/ch-2.hs +++ b/challenge-192/alexander-pankoff/haskell/ch-2.hs @@ -4,6 +4,7 @@ module Main where import Test.HUnit import Data.List (singleton) +import GHC.Natural (Natural) main = runTestTT $ TestList @@ -18,12 +19,16 @@ main = runTestTT (Just 0) (equalDistribution $ singleton 4)] -equalDistribution :: [Int] -> Maybe Int +equalDistribution :: [Int] -> Maybe Natural equalDistribution [] = Just 0 equalDistribution xs = let total = sum xs target = total `div` length xs isDistributable = total `mod` length xs == 0 in if isDistributable - then Just $ sum $ map abs $ scanl (\a b -> a + b - target) 0 xs + then Just + $ fromIntegral + $ sum + $ map abs + $ scanl (\a b -> a + b - target) 0 xs else Nothing
\ No newline at end of file |
