Mailing List Archive

Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
On 26/02/24 12:45 pm, Lawrence D'Oliveiro wrote:
> def score(candidate, answer) :
> return \
> (
> sum(a == b for a, b in zip(candidate, answer)),
> sum
> (
> i != j and a == b
> for i, a in enumerate(candidate)
> for j, b in enumerate(answer)
> )
> )

This is not correct. score((1,1,1), (1,1,2)) gives (2,4). According to
the usual rules of Mastermind, it should be (2, 0).

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list