diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-13 03:17:34 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-13 03:17:34 +0000 |
| commit | 9fc350bc10995405f9908cb950b85eae5ee90b1f (patch) | |
| tree | 2fe7b470bb28f61568aab4cca4193fede8923efa | |
| parent | 8ad5a160d6fc344c435145a7574ab9d8b095cd15 (diff) | |
| parent | 441cfa378fc6df148a2e1ea13c77928401db51ea (diff) | |
| download | perlweeklychallenge-club-9fc350bc10995405f9908cb950b85eae5ee90b1f.tar.gz perlweeklychallenge-club-9fc350bc10995405f9908cb950b85eae5ee90b1f.tar.bz2 perlweeklychallenge-club-9fc350bc10995405f9908cb950b85eae5ee90b1f.zip | |
Merge pull request #3237 from stuart-little/stuart-little_007_haskell
1st commit on 007_haskell
| -rwxr-xr-x | challenge-007/stuart-little/haskell/ch-1.hs | 6 | ||||
| -rwxr-xr-x | challenge-007/stuart-little/haskell/ch-2.hs | 28 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-007/stuart-little/haskell/ch-1.hs b/challenge-007/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..70c993827a --- /dev/null +++ b/challenge-007/stuart-little/haskell/ch-1.hs @@ -0,0 +1,6 @@ +#!/usr/bin/env runghc + +-- run <script> + +main = do + mapM_ print $ let digSum x = sum $ map (\d-> read [d]::Int) $ show x in (0:) $ filter (\x -> mod x (digSum x) == 0) [1..50] diff --git a/challenge-007/stuart-little/haskell/ch-2.hs b/challenge-007/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..4ff8c03e56 --- /dev/null +++ b/challenge-007/stuart-little/haskell/ch-2.hs @@ -0,0 +1,28 @@ +#!/usr/bin/env runghc + +-- run <script> <word1> <word2> <path-to-file> + +import System.Environment (getArgs,) +import Data.List (delete,) +import Data.List.Extra (minimumOn,notNull,) +import Math.TreeFun.Tree (boolToInt,) +import Control.Monad (liftM,) + +dist1 :: Eq a => [a] -> [a] -> Bool +dist1 xs ys = ((length xs) == (length ys)) && ((==) 1 $ sum $ map boolToInt $ zipWith (/=) xs ys) + +shortestLadder :: String -> String -> [String] -> [String] +shortestLadder w1 w2 ws + |(notElem w1 ws) || (notElem w2 ws) =[] + |w1 == w2 =[w1] + |otherwise = let + wsshort = delete w1 ws + l = map (w1:) $ filter (notNull) $ map (\w -> shortestLadder w w2 wsshort) $ filter (dist1 w1) wsshort + in + if (null l) then [] + else (minimumOn length l) + +main = do + (w1:w2:file:_) <- getArgs + ws <- liftM words $ readFile file + putStrLn $ unwords $ shortestLadder w1 w2 ws |
