Wordle comparison: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: Pruned out a redundant zip) |
m (→{{header|Python}}: Slight reduction of main function, minor edits to comments.) |
||
Line 454: | Line 454: | ||
0 for for character not seen in the target |
0 for for character not seen in the target |
||
''' |
''' |
||
residue, matches = mapAccumL(green)([])( |
|||
zip(target, guess) |
|||
⚫ | |||
return mapAccumL(amber)( |
return mapAccumL(amber)( |
||
*first(charCounts)( |
|||
)( |
mapAccumL(green)( |
||
[], zip(target, guess) |
|||
) |
|||
) |
|||
)[1] |
)[1] |
||
Line 467: | Line 466: | ||
def green(residue, tg): |
def green(residue, tg): |
||
'''The existing residue of unmatched characters, tupled |
'''The existing residue of unmatched characters, tupled |
||
with a 2 if the target |
with a character score of 2 if the target character |
||
match. |
and guess character match. |
||
Otherwise, a residue (extended by the unmatched |
Otherwise, a residue (extended by the unmatched |
||
character) tupled with a 0. |
character) tupled with a character score of 0. |
||
''' |
''' |
||
t, g = tg |
t, g = tg |
||
Line 566: | Line 565: | ||
{} |
{} |
||
) |
) |
||
# first :: (a -> b) -> ((a, c) -> (b, c)) |
|||
def first(f): |
|||
'''A simple function lifted to a function over a tuple, |
|||
with f applied only the first of two values. |
|||
⚫ | |||
return lambda xy: (f(xy[0]), xy[1]) |
|||
Line 591: | Line 598: | ||
f(a[0], x) |
f(a[0], x) |
||
) |
) |
||
return lambda acc |
return lambda acc, xs: reduce( |
||
nxt, xs, (acc, []) |
nxt, xs, (acc, []) |
||
) |
) |