diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-18 07:51:59 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-18 07:51:59 -0500 |
| commit | c080973091f1b56a357e6e9e8b990e2bd13d4e2a (patch) | |
| tree | 61d0a3d263aa79defe556fa6c8730a3cf855bc03 | |
| parent | 754e6dcd79dde5387229a23ae7eca35d70eac4a3 (diff) | |
| download | perlweeklychallenge-club-c080973091f1b56a357e6e9e8b990e2bd13d4e2a.tar.gz perlweeklychallenge-club-c080973091f1b56a357e6e9e8b990e2bd13d4e2a.tar.bz2 perlweeklychallenge-club-c080973091f1b56a357e6e9e8b990e2bd13d4e2a.zip | |
1st commit on 096_haskell
| -rwxr-xr-x | challenge-096/stuart-little/haskell/ch-1.hs | 9 | ||||
| -rwxr-xr-x | challenge-096/stuart-little/haskell/ch-2.hs | 21 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-096/stuart-little/haskell/ch-1.hs b/challenge-096/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..8c8c21e92e --- /dev/null +++ b/challenge-096/stuart-little/haskell/ch-1.hs @@ -0,0 +1,9 @@ +#!/usr/bin/env runghc + +-- run <script> <quoted string> + +import System.Environment (getArgs,) + +main = do + str <- getArgs >>= return.head + putStrLn $ unwords $ reverse $ words str diff --git a/challenge-096/stuart-little/haskell/ch-2.hs b/challenge-096/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..6e81b6ee42 --- /dev/null +++ b/challenge-096/stuart-little/haskell/ch-2.hs @@ -0,0 +1,21 @@ +#!/usr/bin/env runghc + +{- +run <script> <space-separated strings> + +implements the simple-minded recursion described at +https://en.wikipedia.org/wiki/Edit_distance#Computation +-} + +import System.Environment (getArgs,) + +levDist :: Eq a => [a] -> [a] -> Int +levDist s1 s2 = d (length s1) (length s2) where + d :: Int -> Int -> Int + d x y |x*y == 0 =x+y + d x y = let extraTerm = if (s1 !! (x-1) == s2 !! (y-1)) then 0 else 1 + in minimum [(1+d (x-1) y),(1+d x (y-1)),(extraTerm + d (x-1) (y-1))] + +main = do + (s1:s2:_) <- getArgs + print $ levDist s1 s2 |
