Skip to content

Instantly share code, notes, and snippets.

@ekmett
Last active January 25, 2022 06:38
Show Gist options
  • Save ekmett/9e8f64744e33c30b589e667c06ae8cc1 to your computer and use it in GitHub Desktop.
Save ekmett/9e8f64744e33c30b589e667c06ae8cc1 to your computer and use it in GitHub Desktop.
rough initial wordle guess calculator
{-# language BlockArguments, TupleSections #-}
import Data.Array
import Data.Foldable
import Data.Char
import Prelude as P
type Pattern = Int
-- each pattern is an equivalence class of words, basically a color pattern.
-- for a 5 character guess and actual word the result is between 0 and 242 inclusive.
score :: String -> String -> Pattern
score xs0 ys0 = go xs0 ys0 where
go (x:xs) (y:ys)
| x == y = 3 * go xs ys + 2
| x `elem` ys0 = 3 * go xs ys + 1
| otherwise = 3 * go xs ys
go [] [] = 0
main = do
ws <- P.filter (not . isUpper . head) . P.filter (\x -> length x == 5) . lines <$> readFile "/usr/share/dict/words"
for_ ws \xs -> do
let worst = maximum $ accumArray (+) 0 (0,242) $ (,1) . score xs <$> ws
putStrLn $ xs ++ " " ++ show worst
-- i just dumped this out to a file and then used
-- $ sort -n -k 2 scores.txt | head -10
-- to peek at the result
@jackpal
Copy link

jackpal commented Jan 25, 2022

FWIW I don't think your score function handles "right letter in wrong position" scores correctly.

Here's an example of a correct scoring function:

https://github.com/TylerGlaiel/wordlebot/blob/45517ab921c1dec6280d0aea9b9f899bc665adb7/wordlebot.cpp#L75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment