diff --git a/src/Julia/005.jl b/src/Julia/005.jl new file mode 100644 index 0000000..dbd11a2 --- /dev/null +++ b/src/Julia/005.jl @@ -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)