aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-16 22:05:02 +0100
committerGitHub <noreply@github.com>2024-06-16 22:05:02 +0100
commit90e167d390089bb3a06f68a24fbd47376bc2b1a4 (patch)
tree11d0d1abf136d45c01acefaeff6453ab24e3b0d9
parente7c6e4694cbc20e39268624c74ec9d5134bd66b7 (diff)
parent3da913aa7a46dfb0f7ae486cd6b691d60a20d0b5 (diff)
downloadperlweeklychallenge-club-90e167d390089bb3a06f68a24fbd47376bc2b1a4.tar.gz
perlweeklychallenge-club-90e167d390089bb3a06f68a24fbd47376bc2b1a4.tar.bz2
perlweeklychallenge-club-90e167d390089bb3a06f68a24fbd47376bc2b1a4.zip
Merge pull request #10265 from jmaslak/jmaslak-challenge-273
Add golang solution for Joelle Maslak
-rw-r--r--challenge-273/joelle-maslak/go/cmd/go-ch-1/main.go27
-rw-r--r--challenge-273/joelle-maslak/go/cmd/go-ch-2/main.go27
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-273/joelle-maslak/go/cmd/go-ch-1/main.go b/challenge-273/joelle-maslak/go/cmd/go-ch-1/main.go
new file mode 100644
index 0000000000..ad5b1d29b0
--- /dev/null
+++ b/challenge-273/joelle-maslak/go/cmd/go-ch-1/main.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "strings"
+)
+
+func main() {
+ if len(os.Args) != 3 || len(os.Args[1]) < 1 || len(os.Args[2]) != 1 {
+ usage()
+ return
+ }
+
+ strlen := float32(len(os.Args[1]))
+ cnt := float32(strings.Count(os.Args[1], os.Args[2]))
+ fmt.Printf("Percentage of times character appears in string: %.0f%%\n", 100.0*cnt/strlen)
+}
+
+func usage() {
+ fmt.Fprintln(os.Stderr, "Usage:")
+ fmt.Fprintln(os.Stderr, "")
+ fmt.Fprintln(os.Stderr, "Calculates the percentage of characters in a string match a given character")
+ fmt.Fprintln(os.Stderr, "")
+ fmt.Fprintln(os.Stderr, " "+os.Args[0]+" <str> <char>")
+ fmt.Fprintln(os.Stderr, "")
+}
diff --git a/challenge-273/joelle-maslak/go/cmd/go-ch-2/main.go b/challenge-273/joelle-maslak/go/cmd/go-ch-2/main.go
new file mode 100644
index 0000000000..34ec86fb63
--- /dev/null
+++ b/challenge-273/joelle-maslak/go/cmd/go-ch-2/main.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "regexp"
+)
+
+func main() {
+ if len(os.Args) != 2 {
+ usage()
+ return
+ }
+
+ // check, _ := regexp.Match(`m/^[^b]*b[^b]/`, []byte(os.Args[1]))
+ check, _ := regexp.Match("^[^b]*b([^a]|$)", []byte(os.Args[1]))
+ fmt.Printf("Output: %t\n", check)
+}
+
+func usage() {
+ fmt.Fprintln(os.Stderr, "Usage:")
+ fmt.Fprintln(os.Stderr, "")
+ fmt.Fprintln(os.Stderr, "Calculate whether there is a 'b' in a string where the first 'b' isn't followed by an 'a'")
+ fmt.Fprintln(os.Stderr, "")
+ fmt.Fprintln(os.Stderr, " "+os.Args[0]+" <str>")
+ fmt.Fprintln(os.Stderr, "")
+}