adventofcode/day10/main.go

32 lines
645 B
Go

package main
import (
"fmt"
"sort"
"strconv"
"strings"
"io/ioutil"
)
func main() {
d, _ := ioutil.ReadFile("input")
strings := strings.Split(string(d),"\n")
var ints []int
for _, s := range strings {
i, err := strconv.Atoi(s)
if err == nil {
ints = append(ints, i)
}
}
sort.Ints(ints)
counts := make(map[int]int)
ints = append(ints, ints[len(ints)-1]+3) // add the phone
prev := 0
for _, c := range ints {
d := c - prev
prev = c
counts[d] += 1
}
fmt.Println("Part 1:", counts[1] * counts[3]) // add the final one
}