-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathp16_15.py
More file actions
27 lines (22 loc) · 693 Bytes
/
p16_15.py
File metadata and controls
27 lines (22 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def master_mind_check(answer: str, guess: str):
hits = 0
pseudo_hits = 0
unhit_colours_ans = set()
unhit_colours_guess = set()
for i in range(len(answer)):
if answer[i] == guess[i]:
hits += 1
else:
unhit_colours_ans.add(answer[i])
unhit_colours_guess.add(guess[i])
pseudo_hits = len(unhit_colours_ans & unhit_colours_guess)
return hits, pseudo_hits
if __name__ == "__main__":
exs = [
("RGBY", "GGRR"),
("RGBY", "RBGY"),
("RRYY", "RYGY")
]
for ans, guess in exs:
print(
f"For ans {ans}, guess {guess} has hits, pseudos: {master_mind_check(ans,guess)}")