aboutsummaryrefslogtreecommitdiff
path: root/challenge-001
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-05-08 22:03:02 +0100
committerGitHub <noreply@github.com>2022-05-08 22:03:02 +0100
commitecb9e456360be235177b48a5e8e1bbfab11148bf (patch)
tree525a32021725002a8a83d8b1cff9795894b2fb81 /challenge-001
parentab3427c64903d92513f161ad5e8cfcb4a69c6453 (diff)
parente7a86e0aa13e0fb34edd4ae0cdd30d4d5f51e130 (diff)
downloadperlweeklychallenge-club-ecb9e456360be235177b48a5e8e1bbfab11148bf.tar.gz
perlweeklychallenge-club-ecb9e456360be235177b48a5e8e1bbfab11148bf.tar.bz2
perlweeklychallenge-club-ecb9e456360be235177b48a5e8e1bbfab11148bf.zip
Merge pull request #6071 from pokgopun/pwc001
pwc001 solution in go
Diffstat (limited to 'challenge-001')
-rw-r--r--challenge-001/pokgopun/README1
-rw-r--r--challenge-001/pokgopun/go/ch-1.go13
-rw-r--r--challenge-001/pokgopun/go/ch-2.go47
3 files changed, 61 insertions, 0 deletions
diff --git a/challenge-001/pokgopun/README b/challenge-001/pokgopun/README
new file mode 100644
index 0000000000..33dfd303a4
--- /dev/null
+++ b/challenge-001/pokgopun/README
@@ -0,0 +1 @@
+Solution by PokGoPun
diff --git a/challenge-001/pokgopun/go/ch-1.go b/challenge-001/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..41e9fb4fb6
--- /dev/null
+++ b/challenge-001/pokgopun/go/ch-1.go
@@ -0,0 +1,13 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+)
+
+func main() {
+ s := "Perl Weekly Challenge"
+ l := "e"
+ fmt.Printf("%q has %q replaced with %q for %v times and resulted in %q\n",
+ s, l, strings.ToUpper(l), strings.Count(s, l), strings.ReplaceAll(s, l, strings.ToUpper(l)))
+}
diff --git a/challenge-001/pokgopun/go/ch-2.go b/challenge-001/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..fdeeab5d4c
--- /dev/null
+++ b/challenge-001/pokgopun/go/ch-2.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "strconv"
+)
+
+var (
+ rseen [15]bool
+ r2str [15]string
+)
+
+func main() {
+ w := bufio.NewWriter(os.Stdout)
+ n, _ := strconv.Atoi(append(os.Args, "20")[1])
+ for i := 1; i <= n; i++ {
+ fmt.Fprintf(w, "%v ", fizzbuzz(i))
+ }
+ w.Flush()
+ fmt.Print("\n")
+}
+
+func fizzbuzz(n int) (str string) {
+ r := n % 15
+ if rseen[r] {
+ str = r2str[r]
+ if str == "" {
+ return strconv.Itoa(n)
+ }
+ return str
+ }
+ rseen[r] = true
+ switch {
+ case r == 0:
+ str = "fizzbuzz"
+ case r%3 == 0:
+ str = "fizz"
+ case r%5 == 0:
+ str = "buzz"
+ default:
+ return strconv.Itoa(n)
+ }
+ r2str[r] = str
+ return str
+}