Wordle チートプログラム
Wordle を純粋に楽しみたい人向きではありません。^^;
ズルしたい人向き(ただし、必勝の保証はありません)
code:ghci
>> wordle
? <guess> <match pattern>
具体例: 最初に arose と予測して、それに対するWordleの応答が、黒黄黒黄緑 だったら、
code:ghci
>> wordle
? arose bybyg
とすると
code:ghci
serge
serve
shire
spire
spree
surge
? |
のように、次の候補一覧がでます。
code:Wordle.hs
module Wordle
where
import Control.Monad.IO.Class
import Data.Bool
import Data.Char
import System.Console.Haskeline
dict5 = filter (all isAscii) . filter (all isLower)
. filter ((5 ==) . length) . words <$> readFile "/usr/share/dict/words"
wordle :: IO ()
wordle = runInputT defaultSettings . loop =<< dict5
where
loop :: String -> InputT IO () loop ws = do
minput <- getInputLine "? "
case minput of
Nothing -> return ()
Just ":q" -> return ()
Just input -> do
let ws' = case words input of
guess:pat:_ -> buildFilter guess pat ws
liftIO $ putStr $ unlines ws'
loop ws'
matchPat :: String -> String -> String
matchPat guess str
= case zipWith phi guess str of
str1 -> zipWith (psi str1) guess str1
where
phi x y = bool y ' ' (x == y)
psi zs x y
| y == ' ' = 'g'
| x elem zs = 'y'
| otherwise = 'b'
buildFilter _ "" = id
buildFilter guess pat = filter p
where
p w = pat == matchPat guess w