-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3p2.go
43 lines (36 loc) · 785 Bytes
/
d3p2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"github.com/Pramod-Devireddy/go-exprtk"
)
func mul(a, b int) int {
return a * b
}
func main() {
scan := bufio.NewScanner(os.Stdin)
exprtkObj := exprtk.NewExprtk()
defer exprtkObj.Delete()
var sum int
enable := true
validExp := regexp.MustCompile(`mul\([0-9]{1,3},[0-9]{1,3}\)|don't\(\)|do\(\)`)
for scan.Scan() {
expInstances := validExp.FindAll([]byte(scan.Text()), -1)
for _, exp := range expInstances {
if string(exp) == "don't()" {
enable = false
} else if string(exp) == "do()" {
enable = true
} else {
if enable == true {
exprtkObj.SetExpression(string(exp))
exprtkObj.CompileExpression()
sum += int(exprtkObj.GetEvaluatedValue())
}
}
}
}
fmt.Println(sum)
}