diff options
Diffstat (limited to 'challenge-112')
| -rwxr-xr-x | challenge-112/stuart-little/haskell/ch-1.hs | 18 | ||||
| -rwxr-xr-x | challenge-112/stuart-little/haskell/ch-2.hs | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-112/stuart-little/haskell/ch-1.hs b/challenge-112/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..fcb3175e7c --- /dev/null +++ b/challenge-112/stuart-little/haskell/ch-1.hs @@ -0,0 +1,18 @@ +#!/usr/bin/env runghc + +-- run <script> <path> + +import System.Environment (getArgs) +import System.FilePath (normalise) +import Text.RegexPR (subRegexPR) + +normDdots :: String -> String +normDdots pth = head $ dropWhile (\x -> norm1dd x /= x) $ iterate norm1dd pth where + norm1dd = normalise . (subRegexPR "(?<=/)[^/.]+/+\\.\\." "") + +stripTrail :: String -> String +stripTrail s = if l=='/' then init s else s where + l = last s + +main :: IO () +main = getArgs >>= putStrLn . stripTrail . normDdots . normalise . head diff --git a/challenge-112/stuart-little/haskell/ch-2.hs b/challenge-112/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..ef4416b79d --- /dev/null +++ b/challenge-112/stuart-little/haskell/ch-2.hs @@ -0,0 +1,18 @@ +#!/usr/bin/env runghc + +-- run <script> <number> + +import Data.List (intercalate) +import System.Environment (getArgs) + +memoSteps :: Int -> [[Int]] +memoSteps = (map memo [0 ..] !!) + where memo 0 = [[1]] + memo 1 = [[1,1],[2]] + memo n = (map (1:) $ memoSteps (n-1)) ++ (map (2:) $ memoSteps (n-2)) + +main = do + nr <- getArgs >>= return . (read::String->Int) . head + let res = memoSteps (nr-1) + putStrLn $ (show $ length res) ++ "\n" ++ (replicate 12 '-') + putStrLn $ intercalate "\n" $ map unwords $ (map.map) show res |
