aboutsummaryrefslogtreecommitdiff
path: root/challenge-088
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-02 21:43:39 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-02 21:43:39 -0500
commiteff2e41f3e2330d76863d78164aa2da7b43ed8fa (patch)
treeb3ba7c2c275d8f12127d65ff5fbba6a471a4c871 /challenge-088
parent6b818f548752d09d25039d06e21a015bef8e82b1 (diff)
downloadperlweeklychallenge-club-eff2e41f3e2330d76863d78164aa2da7b43ed8fa.tar.gz
perlweeklychallenge-club-eff2e41f3e2330d76863d78164aa2da7b43ed8fa.tar.bz2
perlweeklychallenge-club-eff2e41f3e2330d76863d78164aa2da7b43ed8fa.zip
1st commit on 088_haskell
Diffstat (limited to 'challenge-088')
-rwxr-xr-xchallenge-088/stuart-little/haskell/ch-1.hs13
-rwxr-xr-xchallenge-088/stuart-little/haskell/ch-2.hs19
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-088/stuart-little/haskell/ch-1.hs b/challenge-088/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..b623182de8
--- /dev/null
+++ b/challenge-088/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,13 @@
+#!/usr/bin/env runghc
+
+-- run as <script> <space-separated numbers>
+
+import System.Environment
+import Data.List
+
+prods xs = map (\p -> (product $ fst p) * (product $ tail $ snd p)) $ map ((flip splitAt) xs) [0..length xs-1]
+
+main = do
+ args <- getArgs
+ let xs = map (read::String->Int) args
+ putStrLn $ unwords $ map show $ prods xs
diff --git a/challenge-088/stuart-little/haskell/ch-2.hs b/challenge-088/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..6fa6b53a78
--- /dev/null
+++ b/challenge-088/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,19 @@
+#!/usr/bin/env runghc
+
+-- run as <script> <nr_rows nr_columns, space-separated>
+
+import System.Environment
+import Data.List
+import Data.List.Split
+
+pp mat = intercalate "\n" $ map unwords $ (map . map) show mat
+
+spiral mat acc
+ |null mat = acc
+ |otherwise = spiral (reverse $ transpose $ tail mat) (acc ++ (head mat))
+
+main = do
+ args <- getArgs
+ let rows:cols:_ = map (read::String->Int) args
+ mat = chunksOf cols [1..(rows*cols)]
+ putStrLn ("\nOriginal matrix:\n" ++ (pp mat) ++ "\nSpiral:\n" ++ (unwords $ map show $ spiral mat []) ++ "\n")