aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-10 16:08:07 +0000
committerGitHub <noreply@github.com>2021-01-10 16:08:07 +0000
commit109bb4dfeffa9791c25b24503908ca3d187c6bf2 (patch)
tree72624c0aa4005089416641a3ab4a138f3f4c3ae8
parent34a17f3afd2bbd0177ef1a3a1534955b5a6877c0 (diff)
parent327b5b0484205fcc32143bb01c5947df9018c129 (diff)
downloadperlweeklychallenge-club-109bb4dfeffa9791c25b24503908ca3d187c6bf2.tar.gz
perlweeklychallenge-club-109bb4dfeffa9791c25b24503908ca3d187c6bf2.tar.bz2
perlweeklychallenge-club-109bb4dfeffa9791c25b24503908ca3d187c6bf2.zip
Merge pull request #3206 from stuart-little/stuart-little_060_haskell
1st commit on 060_haskell
-rwxr-xr-xchallenge-060/stuart-little/haskell/ch-1.hs14
-rwxr-xr-xchallenge-060/stuart-little/haskell/ch-2.hs16
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-060/stuart-little/haskell/ch-1.hs b/challenge-060/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..ba44fff23d
--- /dev/null
+++ b/challenge-060/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,14 @@
+#!/usr/bin/env runghc
+
+-- run <script> <number or column name>
+
+import System.Environment (getArgs,)
+import Data.Char (toUpper,)
+
+alph = map (\x -> [x]) ['A'..'Z']
+excel = concat $ map (\nr -> map concat $ sequence $ replicate nr alph) [1..]
+
+main = do
+ args <- getArgs
+ let inpt = map toUpper (args !! 0)
+ putStrLn $ unwords $ head $ dropWhile (notElem inpt) $ zipWith (\x y -> [x,y]) (map show [1..]) excel
diff --git a/challenge-060/stuart-little/haskell/ch-2.hs b/challenge-060/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..2d18c9a538
--- /dev/null
+++ b/challenge-060/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,16 @@
+#!/usr/bin/env runghc
+
+-- run <script> <nr_digits> <upper_bound> <space-separated numbers>
+
+import System.Environment (getArgs,)
+import Data.List ((\\),intersect,isPrefixOf,)
+
+canParse :: Eq a => [a] -> [[a]] -> Bool
+canParse xs xss
+ |null xs =True
+ |otherwise = any (\ys -> canParse (xs \\ ys) xss) $ filter (\ys -> isPrefixOf ys xs) xss
+
+main = do
+ (nrdig_str:upperbd_str:nrs) <- getArgs
+ let (nrdig:upperbd:_) = map (read::String->Int) (nrdig_str:[upperbd_str])
+ print $ filter (\nr -> canParse (show nr) nrs) $ intersect [0..upperbd-1] [10^(nrdig-1)..10^nrdig-1]