aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-06-14 11:34:38 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-06-14 11:34:38 -0400
commit4824192800cb30406db585dc788ef87a5e4511fe (patch)
tree478d489043453ccc9fa009e086d8412e7686364e
parentdad6bcabbefc743b091695a82fcfb92342397e38 (diff)
downloadperlweeklychallenge-club-4824192800cb30406db585dc788ef87a5e4511fe.tar.gz
perlweeklychallenge-club-4824192800cb30406db585dc788ef87a5e4511fe.tar.bz2
perlweeklychallenge-club-4824192800cb30406db585dc788ef87a5e4511fe.zip
1st commit on 117_haskell
-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