From 3da913aa7a46dfb0f7ae486cd6b691d60a20d0b5 Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Sat, 15 Jun 2024 17:33:52 -0600 Subject: Add golang solution for Joelle Maslak --- challenge-273/joelle-maslak/go/cmd/go-ch-1/main.go | 27 ++++++++++++++++++++++ challenge-273/joelle-maslak/go/cmd/go-ch-2/main.go | 27 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 challenge-273/joelle-maslak/go/cmd/go-ch-1/main.go create mode 100644 challenge-273/joelle-maslak/go/cmd/go-ch-2/main.go 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]+" ") + 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]+" ") + fmt.Fprintln(os.Stderr, "") +} -- cgit