diff options
| author | ealvar3z <55966724+ealvar3z@users.noreply.github.com> | 2023-01-10 00:54:56 -0800 |
|---|---|---|
| committer | ealvar3z <55966724+ealvar3z@users.noreply.github.com> | 2023-01-10 00:54:56 -0800 |
| commit | 662bb9eca6360a0b973474b155dc4c1f256fff22 (patch) | |
| tree | c9f17cf14a4598cc071048d8f58f1dd6bbd00def | |
| parent | b8a1cd65abd85f6cf9df5b9dc5bc34677763b531 (diff) | |
| download | perlweeklychallenge-club-662bb9eca6360a0b973474b155dc4c1f256fff22.tar.gz perlweeklychallenge-club-662bb9eca6360a0b973474b155dc4c1f256fff22.tar.bz2 perlweeklychallenge-club-662bb9eca6360a0b973474b155dc4c1f256fff22.zip | |
Week 199 Go & Python solutions
| -rw-r--r-- | challenge-199/ealvar3z/go/ch-1.go | 30 | ||||
| -rw-r--r-- | challenge-199/ealvar3z/python/ch-2.py | 21 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-199/ealvar3z/go/ch-1.go b/challenge-199/ealvar3z/go/ch-1.go new file mode 100644 index 0000000000..b4de997100 --- /dev/null +++ b/challenge-199/ealvar3z/go/ch-1.go @@ -0,0 +1,30 @@ +package main + +import "fmt" + +func main() { + tests := [][]int{ + {1, 2, 3, 1, 1, 3}, + {1, 2, 3}, + {1, 1, 1, 1}, + } + for i := range tests { + fmt.Println("Output: ", solve(tests[i])) + } +} + +// Given a list of ints: +// we're asked to find the total count of "Good Pairs" +// A pair(i,j) is good iff list[i] == list[j] && i < j + +// we'll keep a counter of the times we have the value +// in our counter map by looping over each value in the array +func solve(list []int) int { + total := 0 + counter := make(map[int]int) + for _, j := range list { + total += counter[j] + counter[j]++ + } + return total +} diff --git a/challenge-199/ealvar3z/python/ch-2.py b/challenge-199/ealvar3z/python/ch-2.py new file mode 100644 index 0000000000..1ed0a2c97e --- /dev/null +++ b/challenge-199/ealvar3z/python/ch-2.py @@ -0,0 +1,21 @@ +from itertools import combinations + + +def solve(arr, a, b, c): + total = 0 + for i,j,k in combinations(arr,3): + if ((abs(i-j) <= a) and + (abs(j-k) <= b) and + (abs(i-k) <= c)): + total += 1 + return total + + +if __name__ == '__main__': + test1 = [3, 0, 1, 1, 9, 7] + test2 = [1, 1, 2, 2, 3] + a, b, c = [7, 2, 3] + d, e, f = [0, 0, 1] + + print("Output: ", solve(test1, a, b, c)) + print("Output: ", solve(test2, d, e, f)) |
