diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-07-25 20:24:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-25 20:24:06 +0100 |
| commit | 811acc233e7bb609f3af3cc77c068557983c6215 (patch) | |
| tree | 605491032329b0a889912848b0d5656b0a48683d | |
| parent | 642db25a441b301b4e507796c55bfef8a4170185 (diff) | |
| parent | e13783210a31cb796eeb123f1b8130e7f13a158b (diff) | |
| download | perlweeklychallenge-club-811acc233e7bb609f3af3cc77c068557983c6215.tar.gz perlweeklychallenge-club-811acc233e7bb609f3af3cc77c068557983c6215.tar.bz2 perlweeklychallenge-club-811acc233e7bb609f3af3cc77c068557983c6215.zip | |
Merge pull request #6507 from pokgopun/pwc175
pwc175 solution in go
| -rw-r--r-- | challenge-175/pokgopun/go/ch-1.go | 37 | ||||
| -rw-r--r-- | challenge-175/pokgopun/go/ch-2.go | 37 |
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") +} |
