@@ 63,7 63,32 @@ func partA(fn string) {
}
func partB(fn string) {
+ cards := make(map[int]int)
+ for g, l := range getLines(fn) {
+ xs := strings.Split(l, ":")
+ ys := strings.Split(xs[1], "|")
+
+ ws := Ints(ys[0])
+ w := 0
+ for _, i := range Ints(ys[1]) {
+ for _, j := range ws {
+ if i == j {
+ w += 1
+ break
+ }
+ }
+ }
+
+ cards[g] += 1
+ for i := 1; i <= w; i++ {
+ cards[g+i] += cards[g]
+ }
+ }
+
var b int
+ for _, n := range cards {
+ b += n
+ }
log.Printf("%s: %v", fn, b)
}
@@ 71,6 96,6 @@ func main() {
partA("04.example") // 13
partA("04.input") // 32609
- //partB("04.example")
- //partB("04.input")
+ partB("04.example") // 30
+ partB("04.input") // 14624680
}