This commit is contained in:
2022-12-13 15:47:28 +01:00
parent 8becddb3ce
commit d865a9a611
3 changed files with 197 additions and 0 deletions

26
day13/ex2/main.go Normal file
View File

@@ -0,0 +1,26 @@
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)
}