aboutsummaryrefslogtreecommitdiff
path: root/challenge-323/deadmarshal/go
diff options
context:
space:
mode:
authorAli <adeadmarshal@gmail.com>2025-05-26 16:56:02 +0330
committerAli <adeadmarshal@gmail.com>2025-05-26 16:56:02 +0330
commit9e6e9e5f067367edabd91501eb9b94014a40f9f2 (patch)
tree365940c0caf3bb367a330f021fe1a80f15556df2 /challenge-323/deadmarshal/go
parent0729d1308bfe2e7d4fc1ea6f41b40356645d4f72 (diff)
downloadperlweeklychallenge-club-9e6e9e5f067367edabd91501eb9b94014a40f9f2.tar.gz
perlweeklychallenge-club-9e6e9e5f067367edabd91501eb9b94014a40f9f2.tar.bz2
perlweeklychallenge-club-9e6e9e5f067367edabd91501eb9b94014a40f9f2.zip
TWC323
Diffstat (limited to 'challenge-323/deadmarshal/go')
-rw-r--r--challenge-323/deadmarshal/go/ch1.go27
-rw-r--r--challenge-323/deadmarshal/go/ch2.go21
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-323/deadmarshal/go/ch1.go b/challenge-323/deadmarshal/go/ch1.go
new file mode 100644
index 0000000000..afb0c3effc
--- /dev/null
+++ b/challenge-323/deadmarshal/go/ch1.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+)
+
+func incrementDecrement(arr []string) int {
+ x := 0
+ for _, v := range arr {
+ if strings.Contains(v, "++") {
+ x++
+ } else {
+ x--
+ }
+ }
+ return x
+}
+
+func main() {
+ arr1 := []string{"--x", "x++", "x++"}
+ arr2 := []string{"x++", "++x", "x++"}
+ arr3 := []string{"x++", "++x", "--x", "x--"}
+ fmt.Println(incrementDecrement(arr1))
+ fmt.Println(incrementDecrement(arr2))
+ fmt.Println(incrementDecrement(arr3))
+}
diff --git a/challenge-323/deadmarshal/go/ch2.go b/challenge-323/deadmarshal/go/ch2.go
new file mode 100644
index 0000000000..be4b581469
--- /dev/null
+++ b/challenge-323/deadmarshal/go/ch2.go
@@ -0,0 +1,21 @@
+package main
+
+import (
+ "fmt"
+)
+
+func tax_amount(income int, taxes [][]int) float64 {
+ res := 0
+ prev := 0
+ for _, e := range taxes {
+ res += max(0, min(income, e[0])-prev) * e[1]
+ prev = e[0]
+ }
+ return float64(res) / 100.0
+}
+
+func main() {
+ fmt.Println(tax_amount(10, [][]int{{3, 50}, {7, 10}, {12, 25}}))
+ fmt.Println(tax_amount(2, [][]int{{1, 0}, {4, 25}, {5, 50}}))
+ fmt.Println(tax_amount(0, [][]int{{2, 50}}))
+}