aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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