aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manring <michael@manring>2022-07-26 02:11:39 +0700
committerMichael Manring <michael@manring>2022-07-26 02:11:39 +0700
commite13783210a31cb796eeb123f1b8130e7f13a158b (patch)
tree1c189e5fb0e94853e14c5cd1a05dc99a78934dd3
parent440fd5bfe27fdfff4e787bcd8e3b01a51200b266 (diff)
downloadperlweeklychallenge-club-e13783210a31cb796eeb123f1b8130e7f13a158b.tar.gz
perlweeklychallenge-club-e13783210a31cb796eeb123f1b8130e7f13a158b.tar.bz2
perlweeklychallenge-club-e13783210a31cb796eeb123f1b8130e7f13a158b.zip
pwc175 solution in go
-rw-r--r--challenge-175/pokgopun/go/ch-1.go37
-rw-r--r--challenge-175/pokgopun/go/ch-2.go37
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-175/pokgopun/go/ch-1.go b/challenge-175/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..f227332537
--- /dev/null
+++ b/challenge-175/pokgopun/go/ch-1.go
@@ -0,0 +1,37 @@
+/* https://theweeklychallenge.org/blog/perl-weekly-challenge-175/
+Task 1: Last Sunday
+Submitted by: Mohammad S Anwar
+Write a script to list Last Sunday of every month in the given year.
+
+For example, for year 2022, we should get the following:
+
+
+2022-01-30
+2022-02-27
+2022-03-27
+2022-04-24
+2022-05-29
+2022-06-26
+2022-07-31
+2022-08-28
+2022-09-25
+2022-10-30
+2022-11-27
+2022-12-25
+*/
+package main
+
+import (
+ "fmt"
+ "os"
+ "strings"
+ "time"
+
+ "github.com/pokgopun/go/lastweekday"
+)
+
+func main() {
+ var year uint = 2022
+ fmt.Sscanf(strings.Join(os.Args[1:], ""), "%d", &year)
+ fmt.Println(lastweekday.New(time.Sunday, year, "2006-01-02"))
+}
diff --git a/challenge-175/pokgopun/go/ch-2.go b/challenge-175/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..7e805c20b7
--- /dev/null
+++ b/challenge-175/pokgopun/go/ch-2.go
@@ -0,0 +1,37 @@
+/* https://theweeklychallenge.org/blog/perl-weekly-challenge-175/
+Task 2: Perfect Totient Numbers
+Submitted by: Mohammad S Anwar
+Write a script to generate first 20 Perfect Totient Numbers. Please checkout wikipedia page for more informations.
+
+
+Output
+
+3, 9, 15, 27, 39, 81, 111, 183, 243, 255, 327, 363, 471, 729,
+2187, 2199, 3063, 4359, 4375, 5571
+*/
+package main
+
+import (
+ "io"
+ "os"
+ "strconv"
+ "strings"
+
+ "github.com/pokgopun/go/totient"
+)
+
+func main() {
+ p := totient.New()
+ cntdwn := 20
+ var b strings.Builder
+ for i := uint(0); i < 10_000; i++ {
+ if p.IsPerfect(i) {
+ b.WriteString(", " + strconv.FormatUint(uint64(i), 10))
+ cntdwn--
+ }
+ if cntdwn == 0 {
+ break
+ }
+ }
+ io.WriteString(os.Stdout, (b.String()[2:])+"\n")
+}