diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-05-24 20:35:16 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-05-24 20:35:16 +0100 |
| commit | 1b78fa87fafabf6525ceb4ec69003273c1cb7d38 (patch) | |
| tree | 11373062d6adcb8bcc5269e643e62f9d29066d21 | |
| parent | 22b01996d44fc856db6b7594014056e744b964e7 (diff) | |
| download | perlweeklychallenge-club-1b78fa87fafabf6525ceb4ec69003273c1cb7d38.tar.gz perlweeklychallenge-club-1b78fa87fafabf6525ceb4ec69003273c1cb7d38.tar.bz2 perlweeklychallenge-club-1b78fa87fafabf6525ceb4ec69003273c1cb7d38.zip | |
- Added guest contribution by Ulrich Rieke.
| -rw-r--r-- | challenge-166/ulrich-rieke/haskell/ch-1.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-166/ulrich-rieke/haskell/ch-1.hs b/challenge-166/ulrich-rieke/haskell/ch-1.hs new file mode 100644 index 0000000000..fd76269a0b --- /dev/null +++ b/challenge-166/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,38 @@ +module Challenge166 + where +import Data.Maybe ( fromJust ) +import Data.List ( findIndex , (!!) ) +import Data.Char ( isLetter , isDigit ) + +myCondition :: String -> Bool +myCondition str = len > 1 && len < 9 && all (\l -> elem l allowed ) str +where + len :: Int + len = length str + allowed :: [Char] + allowed = ['0'..'9'] ++ ['a' .. 'e'] + +transpose :: String -> String +transpose str = map (\c -> if c `elem` from then shift c else c ) str +where + from :: [Char] + from = ['o', 'l' , 'i' , 's' , 't'] + to :: [Char] + to = ['0' , '1' , '1' , '5' , '7'] + shift :: Char -> Char + shift letter = to !! ( fromJust $ findIndex (== letter) from ) + +pickWord :: String -> String +pickWord str + |myCondition str = str + |myCondition $ transpose str = transpose str + |not $ myCondition str && (not $ myCondition $ transpose str ) = "" + +main :: IO ( ) +main = do + allWords <- readFile "myDictionary.txt" + let singleWords = lines allWords + sanitized = map (\str -> takeWhile (\c -> isDigit c || isLetter c ) str ) + singleWords--an unusual \r appears in the original file which has to be removed + selected = map pickWord sanitized + mapM_ (\w -> putStrLn ( "0#" ++ w)) $ filter ( not . null ) selected |
