adventofcode/02dec/checksum.go

39 lines
451 B
Go
Raw Normal View History

2017-12-02 18:26:28 +00:00
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
}