adventofcode/02dec/checksum.go
2017-12-02 19:26:28 +01:00

39 lines
451 B
Go

package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var sum int
func main() {
in := bufio.NewScanner(os.Stdin)
for in.Scan() {
sum += diff(in.Text())
}
fmt.Println(sum)
}
func diff(l string) int {
var min, max int
for n, s := range strings.Split(l, "\t") {
i, _ := strconv.Atoi(s)
if n == 0 {
min = i
max = i
} else {
if min > i {
min = i
}
if max < i {
max = i
}
}
}
return max - min
}