Files
advent-of-code-2022/day13/ex2/main.go
2022-12-15 14:56:28 +01:00

27 lines
433 B
Go

package main
import (
"aoc2022/day13/common"
"bufio"
"fmt"
"os"
"sort"
)
func main() {
packets := common.ParsePackets(*bufio.NewScanner(os.Stdin), []string{"[[2]]", "[[6]]"})
sort.Slice(packets, func(i int, j int) bool {
return packets[i].Compare(packets[j]) < 0
})
result := 1
for i := 0; i < len(packets); i++ {
if packets[i].IsSeparator() {
result *= (i+1)
}
}
fmt.Println(result)
}