~rootmos/AoC

2a7b2a3dcdb2688a37dcb03d07ba525a8ebe7581 — Gustav Behm 2 months ago 6d83d13
Add solution to AoC 2023 #04b
1 files changed, 27 insertions(+), 2 deletions(-)

M 2023/04.go
M 2023/04.go => 2023/04.go +27 -2
@@ 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
}