Ubuntu系統查找"aeiou"都只出現一次的單詞的程序

module Main where

import Data.Char
import Data.List

main = do
  words <- readFile "/etc/dictionaries-common/words"
  let wordlist = lines words
  mapM_ putStrLn $ filter bestword wordlist
  -- putStrLn $ show $ length $ filter goodword wordlist -- 469
  -- putStrLn $ show $ length $ filter bestword wordlist -- 187


goodword word = all (\c -> elem c $ map toLower word) "aeiou" && notElem '\'' word

bestword word = all (\c -> length (findIndices (`elem` (c:[])) (map toLower word)) == 1) "aeiou" && notElem '\'' word

說好的高亮呢?code

相關文章
相關標籤/搜索