aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-19 19:42:41 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-19 19:42:41 -0500
commit157265a4d6509483939a18a19ff8cbd3faeee6a7 (patch)
treedcf4f5ee29b2cd2f48956d8f65927afcd3d6f410
parent057e2f8c195bbadaddb5f16467d735ffad9f222a (diff)
downloadperlweeklychallenge-club-157265a4d6509483939a18a19ff8cbd3faeee6a7.tar.gz
perlweeklychallenge-club-157265a4d6509483939a18a19ff8cbd3faeee6a7.tar.bz2
perlweeklychallenge-club-157265a4d6509483939a18a19ff8cbd3faeee6a7.zip
1st commit on 048_haskell
-rwxr-xr-xchallenge-048/stuart-little/haskell/ch-1.hs16
-rwxr-xr-xchallenge-048/stuart-little/haskell/ch-2.hs10
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-048/stuart-little/haskell/ch-1.hs b/challenge-048/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..3405cacd78
--- /dev/null
+++ b/challenge-048/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <nr of people; defaults to 50 if you enter nothing>
+
+import Data.List.Extra (headDef,)
+import System.Environment (getArgs,)
+
+surv :: Int -> Int
+surv n
+ |n==1 =1
+ |even n = 2*(surv (div n 2)) -1
+ |odd n = 2*(surv (div n 2)) +1
+
+main = do
+ nrplayers <- getArgs >>= return.(read::String->Int).(headDef "50")
+ print $ surv nrplayers
diff --git a/challenge-048/stuart-little/haskell/ch-2.hs b/challenge-048/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..f7239a04df
--- /dev/null
+++ b/challenge-048/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,10 @@
+#!/usr/bin/env runghc
+
+-- run <script>
+
+import Data.List (sortOn,)
+import Data.Tuple (swap,)
+import Text.Printf (printf,)
+
+main = do
+ mapM_ putStrLn $ sortOn (swap.(splitAt 4)) $ map (\[x,y]-> x ++ y ++ (reverse y) ++ (reverse x)) $ sequence [(map (printf "%02d") ([1..12]::[Int])),["02","12","22"]]