Deutsch English Français Italiano |
<usu3dh$1enrd$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.python Subject: Re: (Mastermind) puzzle (with 3 digits) (Posting On Python-List Prohibited) Date: Thu, 14 Mar 2024 05:53:53 -0000 (UTC) Organization: A noiseless patient Spider Lines: 21 Message-ID: <usu3dh$1enrd$1@dont-email.me> References: <urga12$22ao7$2@dont-email.me> <urgjdt$24v86$1@dont-email.me> <l47r62Fp7gcU1@mid.individual.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 14 Mar 2024 05:53:53 -0000 (UTC) Injection-Info: dont-email.me; posting-host="8a2351749b4eebd2a62c741e1ddb0aa2"; logging-data="1531757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//EH8IrDjejkK64l65NPBz" User-Agent: Pan/0.155 (Kherson; fc5a80b8) Cancel-Lock: sha1:0NWqVZtIuAQltvny2HXr24gPH00= Bytes: 1807 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