diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-25 04:12:49 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-25 04:12:49 +0000 |
| commit | 852652ed9216ab2e95d41b913041d66a9b4de5f4 (patch) | |
| tree | bcfdbb1640b05597ca95baa7806633a6d1ef0c6b | |
| parent | 9d2fe49233c5f4a6a8f18aaa14abbe682a70b6e3 (diff) | |
| parent | 93a7de79a3e3e36456b227eeda5fa5ab5ff89311 (diff) | |
| download | perlweeklychallenge-club-852652ed9216ab2e95d41b913041d66a9b4de5f4.tar.gz perlweeklychallenge-club-852652ed9216ab2e95d41b913041d66a9b4de5f4.tar.bz2 perlweeklychallenge-club-852652ed9216ab2e95d41b913041d66a9b4de5f4.zip | |
Merge pull request #3368 from stuart-little/stuart-little_069_haskell
1st commit on 069_haskell
| -rwxr-xr-x | challenge-069/stuart-little/haskell/ch-1.hs | 32 | ||||
| -rwxr-xr-x | challenge-069/stuart-little/haskell/ch-2.hs | 19 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-069/stuart-little/haskell/ch-1.hs b/challenge-069/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..f490eb5a33 --- /dev/null +++ b/challenge-069/stuart-little/haskell/ch-1.hs @@ -0,0 +1,32 @@ +#!/usr/bin/env runghc + +-- run <script> <lower bound> <upper bound> + +import Data.List (sort,(\\),) +import Data.List.Utils (replace,) +import System.Environment (getArgs,) + +nrDig :: Integer -> Int +nrDig x = ceiling $ logBase 10 $ fromIntegral $ x+1 + +alph :: String +alph = "01689" + +strobHalf :: Int -> [String] +strobHalf n + |n<=1 = sequence [alph] + |even n = sequence $ (alph \\ "0"):(replicate (div n 2 -1) alph) + |odd n = sequence $ ((alph \\ "0"):(replicate (div n 2 -1) alph)) ++ [alph \\ "69"] + +strob :: Int -> [String] +strob n = map (\x -> x ++ rfl n x) $ strobHalf n where + rfl :: Int -> String -> String + rfl n s = replace "#" "9" $ replace "9" "6" $ replace "6" "#" $ reverse $ take (div n 2) s + +strobBds :: Integer -> Integer -> [String] +strobBds low high = filter (\s -> rd s >= low && rd s <= high) $ concat $ map strob [(nrDig low)..(nrDig high)] where + rd = (read::String->Integer) + +main = do + (low:high:_) <- getArgs >>= return.sort.(map (read::String->Integer)) + putStrLn $ unwords $ strobBds low high diff --git a/challenge-069/stuart-little/haskell/ch-2.hs b/challenge-069/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..f691fe58c0 --- /dev/null +++ b/challenge-069/stuart-little/haskell/ch-2.hs @@ -0,0 +1,19 @@ +#!/usr/bin/env runghc + +-- run <script> <N so as to produce S_N; defaults to N=5 if you enter nothing> + +import Data.List.Extra (headDef,replace,) +import System.Environment (getArgs,) + +flp :: String -> String +flp = (replace "#" "1") . (replace "1" "0") . (replace "0" "#") + +iterStr :: Int -> String +iterStr n + |n==0 ="" + |otherwise = s ++ "0" ++ (reverse $ flp s) where + s = iterStr (n-1) + +main = do + n <- getArgs >>= return . (read::String ->Int) . (headDef "5") + putStrLn $ iterStr n |
