diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-13 00:26:31 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-13 00:26:31 -0500 |
| commit | b251ab53893e59f77205203379f48f86827c9ca4 (patch) | |
| tree | 2720a101e5a3cb65fa265091444e5dc25f7b7b88 /challenge-059/stuart-little/haskell | |
| parent | 3d6d1a6bcb4d58dac5c09abb0c4f5bc42f0fa944 (diff) | |
| download | perlweeklychallenge-club-b251ab53893e59f77205203379f48f86827c9ca4.tar.gz perlweeklychallenge-club-b251ab53893e59f77205203379f48f86827c9ca4.tar.bz2 perlweeklychallenge-club-b251ab53893e59f77205203379f48f86827c9ca4.zip | |
1st commit on 059_haskell
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 |
