diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-02-09 22:27:17 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-09 22:27:17 +0000 |
| commit | ac52e2067d781fadbc75368399406c00f7bbc7cb (patch) | |
| tree | 0a1c389a8ec478f8c8828cffe04dd8aff0471544 | |
| parent | eb384dda1ac4923971572a9e3da57b84e79e8f43 (diff) | |
| parent | 784c121a999bee64a5c1ccf7b7ee4f9d04eb7c04 (diff) | |
| download | perlweeklychallenge-club-ac52e2067d781fadbc75368399406c00f7bbc7cb.tar.gz perlweeklychallenge-club-ac52e2067d781fadbc75368399406c00f7bbc7cb.tar.bz2 perlweeklychallenge-club-ac52e2067d781fadbc75368399406c00f7bbc7cb.zip | |
Merge pull request #3489 from stuart-little/stuart-little_099_haskell
1st commit on 099_haskell
| -rwxr-xr-x | challenge-099/stuart-little/haskell/ch-1.hs | 27 | ||||
| -rwxr-xr-x | challenge-099/stuart-little/haskell/ch-2.hs | 10 |
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-099/stuart-little/haskell/ch-1.hs b/challenge-099/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..fece6c8aec --- /dev/null +++ b/challenge-099/stuart-little/haskell/ch-1.hs @@ -0,0 +1,27 @@ +#!/usr/bin/env runghc + +{- +run <script> <string> <singly-quoted pattern> + +- you can escape literal '?' and '*', as in '\?' and '\*' + +- you can also escape literal backslashes: '\\' registers as a single literal backslash, no matter what it's followed by + +any other unescaped instance of the backslash is meaningless: '\x' is just 'x' +-} + +import Data.List (tails) +import Data.List.Extra (notNull) +import System.Environment (getArgs) + +mtch :: String -> String -> Bool +mtch "" "" = True +mtch pat ss |(null pat || null ss) && notNull (pat ++ ss) = False +mtch ('\\':c:ps) (d:ss) = (c==d) && (mtch ps ss) +mtch ('?':ps) (d:ss) = (mtch ps ss) +mtch ('*':ps) ss = any id $ map (mtch ps) $ tails ss +mtch (c:ps) (d:ss) = (c==d) && (mtch ps ss) + +main = do + (str:pat:_) <- getArgs + print $ fromEnum $ mtch pat str diff --git a/challenge-099/stuart-little/haskell/ch-2.hs b/challenge-099/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..b19e4ef877 --- /dev/null +++ b/challenge-099/stuart-little/haskell/ch-2.hs @@ -0,0 +1,10 @@ +#!/usr/bin/env runghc + +-- run <script> <string1> <string2> + +import Combinatorics (tuples) +import System.Environment (getArgs) + +main = do + (s1:s2:_) <- getArgs + print $ length $ filter (s2==) $ tuples (length s2) s1 |
