adventofcode/02dec/checksum.go
2017-12-02 19:42:50 +01:00

34 lines
416 B
Go

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