Wordle comparison: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Updated output to include raw integer scores)
m (→‎{{header|Haskell}}: Replaced bimap with `first`)
Line 147: Line 147:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.Bifunctor (bimap)
<lang haskell>import Data.Bifunctor (first)
import Data.List (intercalate, mapAccumL)
import Data.List (intercalate, mapAccumL)
import qualified Data.Map.Strict as M
import qualified Data.Map.Strict as M
Line 160: Line 160:
snd $
snd $
uncurry (mapAccumL amber) $
uncurry (mapAccumL amber) $
bimap charCounts (zip guess) $
first charCounts $
mapAccumL green [] (zip target guess)
mapAccumL green [] (zip target guess)


green :: String -> (Char, Char) -> (String, Int)
green :: String -> (Char, Char) -> (String, (Char, Int))
green residue (t, g)
green residue (t, g)
| t == g = (residue, 2)
| t == g = (residue, (g, 2))
| otherwise = (t : residue, 0)
| otherwise = (t : residue, (g, 0))


amber :: Tally -> (Char, Int) -> (Tally, Int)
amber :: Tally -> (Char, Int) -> (Tally, Int)