day22, part2
This commit is contained in:
parent
45d03e5ab3
commit
8be2fa3844
|
@ -13,6 +13,6 @@ func Run() int {
|
||||||
space := NewSpace(byZ)
|
space := NewSpace(byZ)
|
||||||
space.SettleAll()
|
space.SettleAll()
|
||||||
|
|
||||||
result := space.ThirdTimeCountFreeBlocks()
|
result := space.CountChainReactoins()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,31 @@ func (s *Space) ThirdTimeCountFreeBlocks() (result int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Space) CountChainReactoins() (result int) {
|
||||||
|
for rowNum, row := range s.SettledOnZ {
|
||||||
|
for blockNum, _ := range row {
|
||||||
|
newUnsettled := slices.Clone(s.SettledOnZ)
|
||||||
|
for rowNum, row := range newUnsettled {
|
||||||
|
newUnsettled[rowNum] = slices.Clone(row)
|
||||||
|
}
|
||||||
|
newUnsettled[rowNum] = slices.Delete(newUnsettled[rowNum], blockNum, blockNum+1)
|
||||||
|
// and now copy the blocks
|
||||||
|
for rowNum, row := range newUnsettled {
|
||||||
|
for blockNum, block := range row {
|
||||||
|
newBlock := *block
|
||||||
|
newUnsettled[rowNum][blockNum] = &newBlock
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newSpace := NewSpace(newUnsettled)
|
||||||
|
moved := newSpace.SettleAll()
|
||||||
|
result += moved
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Space) SettleAll() (totalMoved int) {
|
func (s *Space) SettleAll() (totalMoved int) {
|
||||||
for i := uint(1); i <= s.MaxZ; i++ {
|
for i := uint(1); i <= s.MaxZ; i++ {
|
||||||
movedAfterLayer := s.SettleZ(i)
|
movedAfterLayer := s.SettleZ(i)
|
||||||
|
|
Loading…
Reference in New Issue