Mastermind en Julia
This commit is contained in:
30
src/Julia/005.jl
Normal file
30
src/Julia/005.jl
Normal 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)
|
||||||
Reference in New Issue
Block a user