diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-19 09:14:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-19 09:14:19 +0000 |
| commit | a365de031d950160a8cebdd1a95d0e05baf09964 (patch) | |
| tree | 6174f1e17d78ea91ee6a2fd9933590f882dee3a8 | |
| parent | 29f232aa862f9494fda39c51ca5d185014e0cebb (diff) | |
| parent | c080973091f1b56a357e6e9e8b990e2bd13d4e2a (diff) | |
| download | perlweeklychallenge-club-a365de031d950160a8cebdd1a95d0e05baf09964.tar.gz perlweeklychallenge-club-a365de031d950160a8cebdd1a95d0e05baf09964.tar.bz2 perlweeklychallenge-club-a365de031d950160a8cebdd1a95d0e05baf09964.zip | |
Merge pull request #3316 from stuart-little/stuart-little_096_haskell
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 |
