aboutsummaryrefslogtreecommitdiff
path: root/challenge-068
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-12 18:18:29 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-12 18:18:29 -0500
commit26e97ac94644e4dfdd7420259b054fed20d4cdbb (patch)
treedf80188e5b984ad79ea752850931978bbeec51b6 /challenge-068
parent4189e0d8c2ea360cd3528920ad992735b2437bce (diff)
downloadperlweeklychallenge-club-26e97ac94644e4dfdd7420259b054fed20d4cdbb.tar.gz
perlweeklychallenge-club-26e97ac94644e4dfdd7420259b054fed20d4cdbb.tar.bz2
perlweeklychallenge-club-26e97ac94644e4dfdd7420259b054fed20d4cdbb.zip
1st commit on 030,068_haskell
Diffstat (limited to 'challenge-068')
-rwxr-xr-xchallenge-068/stuart-little/haskell/ch-1.hs16
-rwxr-xr-xchallenge-068/stuart-little/haskell/ch-2.hs16
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-068/stuart-little/haskell/ch-1.hs b/challenge-068/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..3907763688
--- /dev/null
+++ b/challenge-068/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated 0-1_words, one word per row>
+
+import System.Environment (getArgs,)
+import Data.List (transpose,)
+
+zeroRows :: Ord a => [[a]] -> [[a]]
+zeroRows mat = map (\l -> replicate (length l) (minimum l)) mat
+
+main = do
+ mat <- getArgs
+ putStrLn ((replicate 40 '-') ++ "\nInitial matrix:")
+ mapM_ putStrLn mat
+ putStrLn ((replicate 40 '-') ++ "\nTransformed matrix:")
+ mapM_ putStrLn $ zipWith (zipWith min) (zeroRows mat) (transpose $ zeroRows $ transpose mat)
diff --git a/challenge-068/stuart-little/haskell/ch-2.hs b/challenge-068/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..0a7cef3474
--- /dev/null
+++ b/challenge-068/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated list entries>
+
+import System.Environment (getArgs,)
+import Data.List.Utils (join,)
+
+reorder :: [a] -> [a]
+reorder xs
+ |length xs <= 2 =xs
+ |otherwise =(head xs:l:(reorder m)) where
+ (m,(l:_)) = splitAt (length xs - 2) $ tail xs
+
+main = do
+ args <- getArgs
+ putStrLn $ join " -> " $ reorder args