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