B:BD[
2.403] → [
2.403:683]
func solveFirst(p polimer) int {
tmp := strings.Builder{}
for i := 0; i < 10; i++ {
for ch := range p.template {
if ch == len(p.template)-1 {
tmp.WriteByte(p.template[ch])
break
}
tmp.WriteByte(p.template[ch])
tmp.WriteByte(p.inserts[p.template[ch:ch+2]])
func solveFirst(p polimer, steps int) int {
var counter = map[string]int{}
for ch := range p.template {
if ch == len(p.template)-1 {
break
}
counter[p.template[ch:ch+2]]++
}
for i := 0; i < steps; i++ {
newcounter := map[string]int{}
for k, v := range counter {
newcounter[string(k[0])+string(p.inserts[k])] += v
newcounter[string(p.inserts[k])+string(k[1])] += v