diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-15 20:21:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-15 20:21:23 +0100 |
| commit | aaf6bb0225f96064aceb72bc8ce074d0e538ea7f (patch) | |
| tree | 0b173fa3c1fc0928f9f9ebcc25d252d2b82f3493 | |
| parent | 26edcfc1d15cc74916d0e2a0f7001b17647b4f46 (diff) | |
| parent | 4824192800cb30406db585dc788ef87a5e4511fe (diff) | |
| download | perlweeklychallenge-club-aaf6bb0225f96064aceb72bc8ce074d0e538ea7f.tar.gz perlweeklychallenge-club-aaf6bb0225f96064aceb72bc8ce074d0e538ea7f.tar.bz2 perlweeklychallenge-club-aaf6bb0225f96064aceb72bc8ce074d0e538ea7f.zip | |
Merge pull request #4260 from stuart-little/stuart-little_117_haskell
1st commit on 117_haskell
| -rwxr-xr-x | challenge-117/stuart-little/haskell/ch-1.hs | 14 | ||||
| -rwxr-xr-x | challenge-117/stuart-little/haskell/ch-2.hs | 20 |
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 |
