aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-24 17:58:48 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-24 17:58:48 -0500
commit93a7de79a3e3e36456b227eeda5fa5ab5ff89311 (patch)
tree5c0e439a7f435eecc0e74de158729377b33a11d3
parente4e6e760dd36a241d55f5be8eaaa95acf95983e4 (diff)
downloadperlweeklychallenge-club-93a7de79a3e3e36456b227eeda5fa5ab5ff89311.tar.gz
perlweeklychallenge-club-93a7de79a3e3e36456b227eeda5fa5ab5ff89311.tar.bz2
perlweeklychallenge-club-93a7de79a3e3e36456b227eeda5fa5ab5ff89311.zip
1st commit on 069_haskell
-rwxr-xr-xchallenge-069/stuart-little/haskell/ch-1.hs32
-rwxr-xr-xchallenge-069/stuart-little/haskell/ch-2.hs19
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