aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-243/pokgopun/go/ch-1.go66
-rw-r--r--challenge-243/pokgopun/go/ch-2.go70
2 files changed, 136 insertions, 0 deletions
diff --git a/challenge-243/pokgopun/go/ch-1.go b/challenge-243/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..3ce659dddc
--- /dev/null
+++ b/challenge-243/pokgopun/go/ch-1.go
@@ -0,0 +1,66 @@
+//# https://theweeklychallenge.org/blog/perl-weekly-challenge-243/
+/*#
+
+Task 1: Reverse Pairs
+
+Submitted by: [50]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given an array of integers.
+
+ Write a script to return the number of reverse pairs in the given
+ array.
+
+ A reverse pair is a pair (i, j) where: a) 0 <= i < j < nums.length and
+ b) nums[i] > 2 * nums[j].
+
+Example 1
+
+Input: @nums = (1, 3, 2, 3, 1)
+Output: 2
+
+(1, 4) => nums[1] = 3, nums[4] = 1, 3 > 2 * 1
+(3, 4) => nums[3] = 3, nums[4] = 1, 3 > 2 * 1
+
+Example 2
+
+Input: @nums = (2, 4, 3, 5, 1)
+Output: 3
+
+(1, 4) => nums[1] = 4, nums[4] = 1, 4 > 2 * 1
+(2, 4) => nums[2] = 3, nums[4] = 1, 3 > 2 * 1
+(3, 4) => nums[3] = 5, nums[4] = 1, 5 > 2 * 1
+
+Task 2: Floor Sum
+#*/
+//# solution by pokgopun@gmail.com
+
+package main
+
+import "fmt"
+
+type nums []int
+
+func (n nums) rpCount() int {
+ c, l := 0, len(n)
+ for i := 0; i < l-1; i++ {
+ for j := i + 1; j < l; j++ {
+ if n[i] > 2*n[j] {
+ c++
+ }
+ }
+ }
+ return c
+}
+
+func main() {
+ for _, data := range []struct {
+ input nums
+ output int
+ }{
+ {nums{1, 3, 2, 3, 1}, 2},
+ {nums{2, 4, 3, 5, 1}, 3},
+ } {
+ fmt.Println(data.input.rpCount() == data.output)
+ }
+}
diff --git a/challenge-243/pokgopun/go/ch-2.go b/challenge-243/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..a9458aec9f
--- /dev/null
+++ b/challenge-243/pokgopun/go/ch-2.go
@@ -0,0 +1,70 @@
+//# https://theweeklychallenge.org/blog/perl-weekly-challenge-243/
+/*#
+
+Task 2: Floor Sum
+
+Submitted by: [51]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given an array of positive integers (>=1).
+
+ Write a script to return the sum of floor(nums[i] / nums[j]) where 0 <=
+ i,j < nums.length. The floor() function returns the integer part of the
+ division.
+
+Example 1
+
+Input: @nums = (2, 5, 9)
+Output: 10
+
+floor(2 / 5) = 0
+floor(2 / 9) = 0
+floor(5 / 9) = 0
+floor(2 / 2) = 1
+floor(5 / 5) = 1
+floor(9 / 9) = 1
+floor(5 / 2) = 2
+floor(9 / 2) = 4
+floor(9 / 5) = 1
+
+Example 2
+
+Input: @nums = (7, 7, 7, 7, 7, 7, 7)
+Output: 49
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 19th November
+ 2023.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+#*/
+//# solution by pokgopun@gmail.com
+
+package main
+
+import "fmt"
+
+type nums []int
+
+func (n nums) floorSum() int {
+ c, l := 0, len(n)
+ for i := 0; i < l; i++ {
+ for j := 0; j < l; j++ {
+ c += n[i] / n[j]
+ }
+ }
+ return c
+}
+
+func main() {
+ for _, data := range []struct {
+ input nums
+ output int
+ }{
+ {nums{2, 5, 9}, 10},
+ {nums{7, 7, 7, 7, 7, 7, 7}, 49},
+ } {
+ fmt.Println(data.input.floorSum() == data.output)
+ }
+}