adventofcode/01dec/invcaptcha.go

31 lines
371 B
Go
Raw Normal View History

2017-12-02 11:20:13 +00:00
package main
import (
"fmt"
"strconv"
"strings"
)
var in string
var p string
var f string
var sum int
func main() {
fmt.Scanf("%s", &in)
for _, d := range strings.Split(in, "") {
if p == "" {
f = d
} else if p == d {
incr, _ := strconv.Atoi(p)
sum += incr
}
p = d
}
if f == p {
incr, _ := strconv.Atoi(p)
sum += incr
}
fmt.Println(sum)
}