Re: (Mastermind) puzzle (with 3 digits) (Posting On Python-List Prohibited)

Liste des GroupesRevenir à cl python 
Sujet : Re: (Mastermind) puzzle (with 3 digits) (Posting On Python-List Prohibited)
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.python
Date : 14. Mar 2024, 06:53:53
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <usu3dh$1enrd$1@dont-email.me>
References : 1 2 3
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On Wed, 28 Feb 2024 17:29:54 +1300, Greg Ewing wrote:

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).

How about this as a more general Mastermind scoring function, then:

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)
                for s in (set(i for i, (a, b) in enumerate(zip(candidate, answer)) if a == b),)
                if i not in s and j not in s
              )
        )
#end score

Date Sujet#  Auteur
14 Mar 24 * Re: (Mastermind) puzzle (with 3 digits) (Posting On Python-List Prohibited)2Lawrence D'Oliveiro
15 Mar 24 `- Re: (Mastermind) puzzle (with 3 digits) (Posting On Python-List Prohibited)1Paul Rubin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal