Mastermind en Python

This commit is contained in:
2026-05-24 10:48:41 +02:00
parent 77f92130bf
commit 51ce912081

26
src/Python/005.py Normal file
View File

@@ -0,0 +1,26 @@
def mastermind(lst_1: list[int], lst_2: list[int]) -> tuple[int, int]:
match = 0
index_match = 0
for idx, element in enumerate(lst_1):
if lst_1[idx] == lst_2[idx]:
index_match += 1
continue
if element in lst_2:
match += 1
return (index_match, match)
check_1 = [2, 6, 0, 7]
check_2 = [1, 4, 0, 6]
print(mastermind(check_1, check_2)) # (1, 1)
check_1 = [2, 6, 0, 7]
check_2 = [3, 5, 9, 1]
print(mastermind(check_1, check_2)) # (0, 0)
check_1 = [2, 6, 0, 7]
check_2 = [1, 6, 0, 4]
print(mastermind(check_1, check_2)) # (2, 0)
check_1 = [2, 6, 0, 7]
check_2 = [2, 6, 0, 7]
print(mastermind(check_1, check_2)) # (4, 0)