aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPok <pok@goyangi>2025-07-29 00:10:37 +0700
committerPok <pok@goyangi>2025-07-29 00:10:37 +0700
commit458f7fe6d0b83bf2ee7d463570178681c60b2da9 (patch)
tree2e84e567f38173fbca85e3394ab613dac8a26f36
parenta8b828a15086116ae82ab9d0168e8e5f9ab81de1 (diff)
downloadperlweeklychallenge-club-458f7fe6d0b83bf2ee7d463570178681c60b2da9.tar.gz
perlweeklychallenge-club-458f7fe6d0b83bf2ee7d463570178681c60b2da9.tar.bz2
perlweeklychallenge-club-458f7fe6d0b83bf2ee7d463570178681c60b2da9.zip
pwc332 solution in go
-rw-r--r--challenge-332/pokgopun/go/ch-1.go59
-rw-r--r--challenge-332/pokgopun/go/ch-2.go79
2 files changed, 138 insertions, 0 deletions
diff --git a/challenge-332/pokgopun/go/ch-1.go b/challenge-332/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..7483a53add
--- /dev/null
+++ b/challenge-332/pokgopun/go/ch-1.go
@@ -0,0 +1,59 @@
+//# https://theweeklychallenge.org/blog/perl-weekly-challenge-332/
+/*#
+
+Task 1: Binary Date
+
+Submitted by: [39]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given a date in the format YYYY-MM-DD.
+
+ Write a script to convert it into binary date.
+
+Example 1
+
+Input: $date = "2025-07-26"
+Output: "11111101001-111-11010"
+
+Example 2
+
+Input: $date = "2000-02-02"
+Output: "11111010000-10-10"
+
+Example 3
+
+Input: $date = "2024-12-31"
+Output: "11111101000-1100-11111"
+
+Task 2: Odd Letters
+#*/
+//# solution by pokgopun@gmail.com
+
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "strings"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+func bd(str string) string {
+ var y, m, d int
+ fmt.Fscanf(strings.NewReader(str), "%d-%d-%d", &y, &m, &d)
+ return fmt.Sprintf("%b-%b-%b", y, m, d)
+}
+
+func main() {
+ for _, data := range []struct {
+ input, output string
+ }{
+ {"2025-07-26", "11111101001-111-11010"},
+ {"2000-02-02", "11111010000-10-10"},
+ {"2024-12-31", "11111101000-1100-11111"},
+ } {
+ io.WriteString(os.Stdout, cmp.Diff(bd(data.input), data.output)) // blank if ok, otherwise show the difference
+ }
+}
diff --git a/challenge-332/pokgopun/go/ch-2.go b/challenge-332/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..5471d37b72
--- /dev/null
+++ b/challenge-332/pokgopun/go/ch-2.go
@@ -0,0 +1,79 @@
+//# https://theweeklychallenge.org/blog/perl-weekly-challenge-332/
+/*#
+
+Task 2: Odd Letters
+
+Submitted by: [40]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given a string.
+
+ Write a script to find out if each letter in the given string appeared
+ odd number of times.
+
+Example 1
+
+Input: $str = "weekly"
+Output: false
+
+w: 1 time
+e: 2 times
+k: 1 time
+l: 1 time
+y: 1 time
+
+The letter 'e' appeared 2 times i.e. even.
+
+Example 2
+
+Input: $str = "perl"
+Output: true
+
+Example 3
+
+Input: $source = "challenge"
+Output: false
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 3rd August
+ 2025.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+#*/
+//# solution by pokgopun@gmail.com
+
+package main
+
+import (
+ "io"
+ "os"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+func ol(str string) bool {
+ m := make(map[rune]int)
+ for _, v := range str {
+ m[v]++
+ }
+ for _, v := range m {
+ if v%2 == 0 {
+ return false
+ }
+ }
+ return true
+}
+
+func main() {
+ for _, data := range []struct {
+ input string
+ output bool
+ }{
+ {"weekly", false},
+ {"perl", true},
+ {"challenge", false},
+ } {
+ io.WriteString(os.Stdout, cmp.Diff(ol(data.input), data.output)) // blank if ok, otherwise show the difference
+ }
+}