aboutsummaryrefslogtreecommitdiff
path: root/challenge-115
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-31 21:35:10 +0100
committerGitHub <noreply@github.com>2021-05-31 21:35:10 +0100
commit59ed78b37ef7db52ec1fc4a2146d18ad06ab490e (patch)
tree671374a13c4881009d9b52ebb23cffc8c234b0f2 /challenge-115
parent153cc91a07a10ef9c76f2103434f60695877957f (diff)
parentb3f0fcda644be528cddc547f351c10b29b8008f6 (diff)
downloadperlweeklychallenge-club-59ed78b37ef7db52ec1fc4a2146d18ad06ab490e.tar.gz
perlweeklychallenge-club-59ed78b37ef7db52ec1fc4a2146d18ad06ab490e.tar.bz2
perlweeklychallenge-club-59ed78b37ef7db52ec1fc4a2146d18ad06ab490e.zip
Merge pull request #4182 from stuart-little/stuart-little_115_haskell
1st commit on 115_haskell
Diffstat (limited to 'challenge-115')
-rwxr-xr-xchallenge-115/stuart-little/haskell/ch-1.hs16
-rwxr-xr-xchallenge-115/stuart-little/haskell/ch-2.hs14
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-115/stuart-little/haskell/ch-1.hs b/challenge-115/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..5253ee7b01
--- /dev/null
+++ b/challenge-115/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated strings>
+
+import Data.List ((\\))
+import System.Environment (getArgs)
+
+canChain :: [String] -> Char -> Char -> Bool
+canChain ws s e
+ |null ws = False
+ |length ws == 1 = ((head.head $ ws) == s) && ((last.head $ ws) == e)
+ |otherwise = any (\w -> canChain (ws \\ [w]) (last w) e) (filter (\w -> head w == s) ws)
+
+main = do
+ ws <- getArgs
+ putStrLn . show . fromEnum $ (canChain (tail ws) (last . head $ ws) (head . head $ ws))
diff --git a/challenge-115/stuart-little/haskell/ch-2.hs b/challenge-115/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..684e4f025c
--- /dev/null
+++ b/challenge-115/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,14 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated digits>
+
+import Data.List (intercalate,sort)
+import System.Environment (getArgs)
+import Text.RegexPR (subRegexPR)
+
+lgstEven :: [String] -> String
+lgstEven digs = if even.(read::String->Int) $ res then res else "No even digits.." where
+ res = (subRegexPR "(.)([13579]*)$" "\\2\\1").(intercalate "").reverse.sort $ digs
+
+main :: IO ()
+main = getArgs >>= putStrLn.lgstEven