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.ListBifunctor (intercalate, mapAccumLbimap)
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 =
in snd $
let (residue, matches) =
uncurry (mapAccumL amber) $
bimap charCounts (zip guess) matches)$
mapAccumL green [] (zip target guess)
in snd $
mapAccumL
amber
(charCounts residue)
(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_)
| 0 < fromMaybe 0 (M.lookup c tally) =
(M.adjust pred c tally, 1)
9,655

edits