Compare commits
4 Commits
77f92130bf
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a37e28de1 | |||
| 78efe71bc0 | |||
| d72b651818 | |||
| 51ce912081 |
57
src/Go/005.go
Normal file
57
src/Go/005.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func mastermind(lst_1 []int, lst_2 []int) (int, int) {
|
||||||
|
indexMatch := 0
|
||||||
|
valueMatch := 0
|
||||||
|
|
||||||
|
for idx, element := range lst_1 {
|
||||||
|
if lst_1[idx] == lst_2[idx] {
|
||||||
|
indexMatch++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
found := false
|
||||||
|
for _, value := range lst_2 {
|
||||||
|
if element == value {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if found {
|
||||||
|
valueMatch++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexMatch, valueMatch
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
{
|
||||||
|
check_1 := []int{2, 6, 0, 7}
|
||||||
|
check_2 := []int{1, 4, 0, 6}
|
||||||
|
result_1, result_2 := mastermind(check_1, check_2)
|
||||||
|
fmt.Println(result_1, result_2) // (1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
check_1 := []int{2, 6, 0, 7}
|
||||||
|
check_2 := []int{3, 5, 9, 1}
|
||||||
|
result_1, result_2 := mastermind(check_1, check_2)
|
||||||
|
fmt.Println(result_1, result_2) // (0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
check_1 := []int{2, 6, 0, 7}
|
||||||
|
check_2 := []int{1, 6, 0, 4}
|
||||||
|
result_1, result_2 := mastermind(check_1, check_2)
|
||||||
|
fmt.Println(result_1, result_2) // (2, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
check_1 := []int{2, 6, 0, 7}
|
||||||
|
check_2 := []int{2, 6, 0, 7}
|
||||||
|
result_1, result_2 := mastermind(check_1, check_2)
|
||||||
|
fmt.Println(result_1, result_2) // (4, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
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)
|
||||||
26
src/Python/005.py
Normal file
26
src/Python/005.py
Normal 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)
|
||||||
34
src/Rust/005.rs
Normal file
34
src/Rust/005.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
fn mastermind(lst_1: &[i32], lst_2: &[i32]) -> (i32, i32) {
|
||||||
|
let mut index_match: i32 = 0;
|
||||||
|
let mut match_value: i32 = 0;
|
||||||
|
|
||||||
|
for idx in 0..lst_1.len() {
|
||||||
|
if lst_1[idx] == lst_2[idx] {
|
||||||
|
index_match += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if lst_2.contains(&lst_1[idx]) {
|
||||||
|
match_value += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(index_match, match_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let check_1 = vec![2, 6, 0, 7];
|
||||||
|
let check_2 = vec![1, 4, 0, 6];
|
||||||
|
println!("{:?}", mastermind(&check_1, &check_2)); // (1, 1)
|
||||||
|
|
||||||
|
let check_1 = vec![2, 6, 0, 7];
|
||||||
|
let check_2 = vec![3, 5, 9, 1];
|
||||||
|
println!("{:?}", mastermind(&check_1, &check_2)); // (0, 0)
|
||||||
|
|
||||||
|
let check_1 = vec![2, 6, 0, 7];
|
||||||
|
let check_2 = vec![1, 6, 0, 4];
|
||||||
|
println!("{:?}", mastermind(&check_1, &check_2)); // (2, 0)
|
||||||
|
|
||||||
|
let check_1 = vec![2, 6, 0, 7];
|
||||||
|
let check_2 = vec![2, 6, 0, 7];
|
||||||
|
println!("{:?}", mastermind(&check_1, &check_2)); // (4, 0)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user