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?
(HenHanna) writes:
1. Could there be a different approach? (not exhaustive search) ?
Yes, this type of puzzle is called a constraint satisfaction problem
(CSP). There is a big literature on how to solve those. Basically you
use the different clues to narrow the search space. There is a language called Prolog which is designed for this type of problem.
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)
)
)
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 6 |
Nodes: | 8 (0 / 8) |
Uptime: | 47:08:30 |
Calls: | 45 |
Files: | 21,492 |
Messages: | 63,554 |