diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-01-18 17:31:04 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-01-18 17:31:04 -0500 |
| commit | 4cfddf0f8585136d645fe7a34e7fc7ce7787b088 (patch) | |
| tree | 66afe0ed603cc3aaa834e433eb8e7204ac4b84a4 /challenge-059/stuart-little/haskell | |
| parent | eacd94671a7799bbb5d9dce6a3bd16ee57ee711b (diff) | |
| parent | 754e6dcd79dde5387229a23ae7eca35d70eac4a3 (diff) | |
| download | perlweeklychallenge-club-4cfddf0f8585136d645fe7a34e7fc7ce7787b088.tar.gz perlweeklychallenge-club-4cfddf0f8585136d645fe7a34e7fc7ce7787b088.tar.bz2 perlweeklychallenge-club-4cfddf0f8585136d645fe7a34e7fc7ce7787b088.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club into master
Diffstat (limited to 'challenge-059/stuart-little/haskell')
| -rwxr-xr-x | challenge-059/stuart-little/haskell/ch-1.hs | 12 | ||||
| -rwxr-xr-x | challenge-059/stuart-little/haskell/ch-2.hs | 17 |
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-059/stuart-little/haskell/ch-1.hs b/challenge-059/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..c84128b8cd --- /dev/null +++ b/challenge-059/stuart-little/haskell/ch-1.hs @@ -0,0 +1,12 @@ +#!/usr/bin/env runghc + +-- run <script> <cutoff_nr> <space-separated list entries> + +import System.Environment (getArgs,) +import Control.Monad (liftM,) +import Data.List (partition,) +import Data.List.Utils (join,) + +main = do + (cut:rest) <- liftM (map (read::String->Int)) getArgs + putStrLn $ join " -> " $ map show $ uncurry (++) $ partition (cut >) rest diff --git a/challenge-059/stuart-little/haskell/ch-2.hs b/challenge-059/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..1269923da7 --- /dev/null +++ b/challenge-059/stuart-little/haskell/ch-2.hs @@ -0,0 +1,17 @@ +#!/usr/bin/env runghc + +-- run <script> <space-separated numbers> + +import System.Environment (getArgs,) +import Control.Monad (liftM,) +import Data.Digits (digitsRev,) +import Data.List (transpose,) +import Data.List.Utils (countElem,) + +diffs :: Int -> [Int] -> Int +diffs l xs = let (zeros,ones,lxs) = (countElem 0 xs,countElem 1 xs,length xs) in + div (l*(l-1) - ones*(ones - 1) - (zeros + l - lxs)*(zeros+l - lxs - 1)) 2 + +main = do + nrs <- liftM (map (read::String->Int)) getArgs + print $ sum $ map (diffs $ length nrs) $ transpose $ map (digitsRev 2) nrs |
