Wordle comparison: Difference between revisions
→{{header|Haskell}}: Used bimap to eliminate a couple of redundant name bindings
(→{{header|Haskell}}: Used bimap to eliminate a couple of redundant name bindings) |
|||
Line 147:
=={{header|Haskell}}==
<lang haskell>import Data.
import Data.List (intercalate, mapAccumL)
import qualified Data.Map.Strict as M
import Data.Maybe (fromMaybe)
Line 157 ⟶ 158:
wordleScore :: String -> String -> [Int]
wordleScore target guess =
uncurry (mapAccumL amber) $
mapAccumL green [] (zip target guess)
▲ in snd $
▲ (zip guess matches)
green :: String -> (Char, Char) -> (String, Int)
Line 172 ⟶ 170:
amber :: Tally -> (Char, Int) -> (Tally, Int)
amber tally (_, 2) = (tally, 2)
amber tally (c,
| 0 < fromMaybe 0 (M.lookup c tally) =
(M.adjust pred c tally, 1)
|