aboutsummaryrefslogtreecommitdiff
path: root/challenge-243/deadmarshal/go
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-11-15 21:53:10 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2023-11-15 21:53:10 +0330
commit7d92a145e089e59f0f830843ba91cd7223bc6c98 (patch)
tree5e0043297d1fde64aa5c75c5e1440c4cbc393389 /challenge-243/deadmarshal/go
parentd20e7296170b997b7e690a58b79156f6c81f1cd2 (diff)
downloadperlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.tar.gz
perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.tar.bz2
perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.zip
TWC243 extra solutions
Diffstat (limited to 'challenge-243/deadmarshal/go')
-rw-r--r--challenge-243/deadmarshal/go/ch1.go24
-rw-r--r--challenge-243/deadmarshal/go/ch2.go22
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/go/ch1.go b/challenge-243/deadmarshal/go/ch1.go
new file mode 100644
index 0000000000..32ff5872e0
--- /dev/null
+++ b/challenge-243/deadmarshal/go/ch1.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "fmt"
+)
+
+func reversePairs(arr []int) int {
+ count := 0
+ for i := 0; i < len(arr)-1; i++ {
+ for j := i + 1; j < len(arr); j++ {
+ if arr[i] > 2*arr[j] {
+ count += 1
+ }
+ }
+ }
+ return count
+}
+
+func main() {
+ arr1 := []int{1, 3, 2, 3, 1}
+ arr2 := []int{2, 4, 3, 5, 1}
+ fmt.Println(reversePairs(arr1))
+ fmt.Println(reversePairs(arr2))
+}
diff --git a/challenge-243/deadmarshal/go/ch2.go b/challenge-243/deadmarshal/go/ch2.go
new file mode 100644
index 0000000000..0d6ef1f80b
--- /dev/null
+++ b/challenge-243/deadmarshal/go/ch2.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "fmt"
+)
+
+func floorSum(arr []int) int {
+ sum := 0
+ for _, v1 := range arr {
+ for _, v2 := range arr {
+ sum += v1 / v2
+ }
+ }
+ return sum
+}
+
+func main() {
+ arr1 := []int{2, 5, 9}
+ arr2 := []int{7, 7, 7, 7, 7, 7, 7}
+ fmt.Println(floorSum(arr1))
+ fmt.Println(floorSum(arr2))
+}