Could you share a short, VERY Readable Pythonic code that solves this?
Could you share a short, VERY Readable Pythonic code that solves this?
Could you share a short, VERY Readable Pythonic code that solves this?def score(candidate, answer) :
I like that approach. Here is my version:
1. Could there be a different approach? (not exhaustive search) ?
2. What's a nice tweak on this problem that
would call for a program that's just a bit longer, harder?
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).
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:
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 57:43:49 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,067 |
Messages: | 6,417,451 |
Posted today: | 1 |