aboutsummaryrefslogtreecommitdiff
path: root/challenge-060
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-10 10:42:57 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-10 10:42:57 -0500
commit327b5b0484205fcc32143bb01c5947df9018c129 (patch)
tree72624c0aa4005089416641a3ab4a138f3f4c3ae8 /challenge-060
parent34a17f3afd2bbd0177ef1a3a1534955b5a6877c0 (diff)
downloadperlweeklychallenge-club-327b5b0484205fcc32143bb01c5947df9018c129.tar.gz
perlweeklychallenge-club-327b5b0484205fcc32143bb01c5947df9018c129.tar.bz2
perlweeklychallenge-club-327b5b0484205fcc32143bb01c5947df9018c129.zip
1st commit on 060_haskell
Diffstat (limited to 'challenge-060')
-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]