Mastermind en Julia

This commit is contained in:
2026-05-24 10:49:01 +02:00
parent 51ce912081
commit d72b651818

30
src/Julia/005.jl Normal file
View File

@@ -0,0 +1,30 @@
function mastermind(lst_1, lst_2)
index_match = 0
match = 0
for (idx, element) in enumerate(lst_1)
if lst_1[idx] == lst_2[idx]
index_match += 1
continue
end
if element in lst_2
match += 1
end
end
return (index_match, match)
end
check_1 = [2, 6, 0, 7]
check_2 = [1, 4, 0, 6]
println(mastermind(check_1, check_2)) # (1, 1)
check_1 = [2, 6, 0, 7]
check_2 = [3, 5, 9, 1]
println(mastermind(check_1, check_2)) # (0, 0)
check_1 = [2, 6, 0, 7]
check_2 = [1, 6, 0, 4]
println(mastermind(check_1, check_2)) # (2, 0)
check_1 = [2, 6, 0, 7]
check_2 = [2, 6, 0, 7]
println(mastermind(check_1, check_2)) # (4, 0)