aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-117/stuart-little/haskell/ch-1.hs14
-rwxr-xr-xchallenge-117/stuart-little/haskell/ch-2.hs20
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-117/stuart-little/haskell/ch-1.hs b/challenge-117/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..29bbd0e452
--- /dev/null
+++ b/challenge-117/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,14 @@
+#!/usr/bin/env runghc
+
+-- run <script> <path-to-file>
+
+import Data.Char (isDigit)
+import Data.List ((\\))
+import System.Environment (getArgs)
+
+missingNr :: [String] -> Int
+missingNr xs = head $ [1..(length xs)] \\ lnnrs where
+ lnnrs = map (read::String->Int) $ map (takeWhile isDigit) $ map (dropWhile (not . isDigit)) xs
+
+main :: IO ()
+main = getArgs >>= readFile . head >>= putStrLn . show . missingNr . lines
diff --git a/challenge-117/stuart-little/haskell/ch-2.hs b/challenge-117/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..08d7611322
--- /dev/null
+++ b/challenge-117/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,20 @@
+#!/usr/bin/env runghc
+
+-- run <script> <number>
+-- https://oeis.org/A006318
+
+import System.Environment (getArgs)
+
+memoPaths :: [[String]]
+memoPaths = map mkPaths [0..]
+
+mkPaths :: Int -> [String]
+mkPaths nr
+ |nr==0 = [""]
+ |nr==1 = ["R","LH"]
+ |otherwise = rs ++ rst where
+ rs = map (('R':)) $ memoPaths !! (nr-1)
+ rst = concat $ map (\x-> map (\xs-> "L" ++ (head xs) ++ "H" ++ (last xs)) $ sequence [(memoPaths !! x), (memoPaths !! (nr-1-x))]) [0..nr-1]
+
+main :: IO ()
+main = getArgs >>= putStrLn.unlines.mkPaths.(read::String->Int).head