Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e8078484a
|
|||
3ff5e90e81
|
|||
ada450ef97
|
|||
c788813cd2
|
|||
788239e531
|
|||
37928d7138
|
|||
da5823aa17
|
|||
8282e09a42
|
|||
343007481a
|
|||
44eeb5a8a6
|
|||
f8d2758c90
|
|||
d9e0d9b649
|
|||
94d83695bf
|
|||
365edf82b1
|
|||
a099a86511
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@
|
|||||||
__debug_bin
|
__debug_bin
|
||||||
aoc2019
|
aoc2019
|
||||||
debug.test
|
debug.test
|
||||||
*.*prof
|
|
||||||
|
@ -28,6 +28,9 @@ func (d *Day02) Part1() string {
|
|||||||
d.setParams(12, 2)
|
d.setParams(12, 2)
|
||||||
d.program.Run()
|
d.program.Run()
|
||||||
|
|
||||||
|
if d.program.GetMemory(0) != 4138658 {
|
||||||
|
panic("")
|
||||||
|
}
|
||||||
return fmt.Sprintf("Position 0 = %s%d%s", utilities.TextBold, d.program.GetMemory(0), utilities.TextReset)
|
return fmt.Sprintf("Position 0 = %s%d%s", utilities.TextBold, d.program.GetMemory(0), utilities.TextReset)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +59,9 @@ func (d *Day02) Part2() string {
|
|||||||
if !found {
|
if !found {
|
||||||
panic("!found")
|
panic("!found")
|
||||||
}
|
}
|
||||||
|
if noun != 72 || verb != 64 {
|
||||||
|
panic("")
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%d created by noun=%d, verb=%d. 100 * noun + verb = %s%d%s",
|
return fmt.Sprintf("%d created by noun=%d, verb=%d. 100 * noun + verb = %s%d%s",
|
||||||
sentinel,
|
sentinel,
|
||||||
|
31
days/10.go
31
days/10.go
@ -45,9 +45,9 @@ func (d Day10) Num() int {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (d Day10) getVisibleAsteroids(i1, j1 int) map[u.Vec2[int]]bool {
|
func (d Day10) getVisibleAsteroids(i1, j1 int) []u.Vec2[int] {
|
||||||
visited := make(map[u.Vec2[int]]bool, 0)
|
visited := make([]u.Vec2[int], 0)
|
||||||
foundAsteroids := make(map[u.Vec2[int]]bool, 0)
|
foundAsteroids := make([]u.Vec2[int], 0)
|
||||||
|
|
||||||
findNext := func(startX, startY, incX, incY int) *u.Vec2[int] {
|
findNext := func(startX, startY, incX, incY int) *u.Vec2[int] {
|
||||||
var found *u.Vec2[int]
|
var found *u.Vec2[int]
|
||||||
@ -59,8 +59,8 @@ func (d Day10) getVisibleAsteroids(i1, j1 int) map[u.Vec2[int]]bool {
|
|||||||
y := startY + incY
|
y := startY + incY
|
||||||
for x < len(d.asteroids) && x >= 0 && y < len(d.asteroids[x]) && y >= 0 {
|
for x < len(d.asteroids) && x >= 0 && y < len(d.asteroids[x]) && y >= 0 {
|
||||||
currPair := u.Vec2[int]{X: x, Y: y}
|
currPair := u.Vec2[int]{X: x, Y: y}
|
||||||
if _, exists := visited[currPair]; !exists {
|
if !u.ArrayContains(visited, currPair) {
|
||||||
visited[currPair] = true
|
visited = append(visited, currPair)
|
||||||
|
|
||||||
if d.asteroids[x][y] {
|
if d.asteroids[x][y] {
|
||||||
if found == nil {
|
if found == nil {
|
||||||
@ -91,16 +91,16 @@ func (d Day10) getVisibleAsteroids(i1, j1 int) map[u.Vec2[int]]bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if found := findNext(i1, j1, incX, incY); found != nil {
|
if found := findNext(i1, j1, incX, incY); found != nil {
|
||||||
foundAsteroids[*found] = true
|
foundAsteroids = append(foundAsteroids, *found)
|
||||||
}
|
}
|
||||||
if found := findNext(i1, j1, incX, -incY); found != nil {
|
if found := findNext(i1, j1, incX, -incY); found != nil {
|
||||||
foundAsteroids[*found] = true
|
foundAsteroids = append(foundAsteroids, *found)
|
||||||
}
|
}
|
||||||
if found := findNext(i1, j1, -incX, incY); found != nil {
|
if found := findNext(i1, j1, -incX, incY); found != nil {
|
||||||
foundAsteroids[*found] = true
|
foundAsteroids = append(foundAsteroids, *found)
|
||||||
}
|
}
|
||||||
if found := findNext(i1, j1, -incX, -incY); found != nil {
|
if found := findNext(i1, j1, -incX, -incY); found != nil {
|
||||||
foundAsteroids[*found] = true
|
foundAsteroids = append(foundAsteroids, *found)
|
||||||
}
|
}
|
||||||
|
|
||||||
incY++
|
incY++
|
||||||
@ -116,8 +116,8 @@ func (d Day10) numVisibleAsteroids(i1, j1 int) int {
|
|||||||
return len(d.getVisibleAsteroids(i1, j1))
|
return len(d.getVisibleAsteroids(i1, j1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Day10) removeAsteroids(locs map[u.Vec2[int]]bool) {
|
func (d *Day10) removeAsteroids(locs ...u.Vec2[int]) {
|
||||||
for loc := range locs {
|
for _, loc := range locs {
|
||||||
if !d.asteroids[loc.X][loc.Y] {
|
if !d.asteroids[loc.X][loc.Y] {
|
||||||
panic("tried to remove non-asteroid")
|
panic("tried to remove non-asteroid")
|
||||||
}
|
}
|
||||||
@ -156,15 +156,14 @@ func (d *Day10) Part2() string {
|
|||||||
|
|
||||||
if vaporized+len(visibleAsteroids) < findNumVaporized {
|
if vaporized+len(visibleAsteroids) < findNumVaporized {
|
||||||
vaporized += len(visibleAsteroids)
|
vaporized += len(visibleAsteroids)
|
||||||
d.removeAsteroids(visibleAsteroids)
|
d.removeAsteroids(visibleAsteroids...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
vecs := u.MapKeys(visibleAsteroids)
|
sort.Slice(visibleAsteroids, func(i, j int) bool {
|
||||||
sort.Slice(vecs, func(i, j int) bool {
|
return d.idealLocation.AngleBetween(visibleAsteroids[i]) > d.idealLocation.AngleBetween(visibleAsteroids[j])
|
||||||
return d.idealLocation.AngleBetween(vecs[i]) > d.idealLocation.AngleBetween(vecs[j])
|
|
||||||
})
|
})
|
||||||
targetLocation = vecs[findNumVaporized-1-vaporized]
|
targetLocation = visibleAsteroids[findNumVaporized-1-vaporized]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
63
days/13.go
63
days/13.go
@ -2,7 +2,6 @@ package days
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
u "parnic.com/aoc2019/utilities"
|
||||||
)
|
)
|
||||||
@ -46,36 +45,36 @@ func (d Day13) getNumBlocks() int {
|
|||||||
return blockTiles
|
return blockTiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Day13) Draw() {
|
// func (d Day13) drawGameBoard() {
|
||||||
s := strings.Builder{}
|
// s := strings.Builder{}
|
||||||
for x := range d.gameBoard {
|
// for x := range d.gameBoard {
|
||||||
for y := range d.gameBoard[x] {
|
// for y := range d.gameBoard[x] {
|
||||||
block := d.gameBoard[x][y]
|
// block := d.gameBoard[x][y]
|
||||||
if block == tileBlock {
|
// if block == tileBlock {
|
||||||
s.WriteString(u.ColorBlue)
|
// s.WriteString(u.ColorBlue)
|
||||||
s.WriteRune('█')
|
// s.WriteRune('█')
|
||||||
s.WriteString(u.TextReset)
|
// s.WriteString(u.TextReset)
|
||||||
} else if block == tileBall {
|
// } else if block == tileBall {
|
||||||
s.WriteString(u.ColorGreen)
|
// s.WriteString(u.ColorGreen)
|
||||||
s.WriteRune('█')
|
// s.WriteRune('█')
|
||||||
s.WriteString(u.TextReset)
|
// s.WriteString(u.TextReset)
|
||||||
} else if block == tileWall {
|
// } else if block == tileWall {
|
||||||
s.WriteString(u.ColorWhite)
|
// s.WriteString(u.ColorWhite)
|
||||||
s.WriteRune('█')
|
// s.WriteRune('█')
|
||||||
s.WriteString(u.TextReset)
|
// s.WriteString(u.TextReset)
|
||||||
} else if block == tileHPaddle {
|
// } else if block == tileHPaddle {
|
||||||
s.WriteString(u.ColorRed)
|
// s.WriteString(u.ColorRed)
|
||||||
s.WriteRune('█')
|
// s.WriteRune('█')
|
||||||
s.WriteString(u.TextReset)
|
// s.WriteString(u.TextReset)
|
||||||
} else if block == tileEmpty {
|
// } else if block == tileEmpty {
|
||||||
s.WriteRune(' ')
|
// s.WriteRune(' ')
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
s.WriteRune('\n')
|
// s.WriteRune('\n')
|
||||||
}
|
// }
|
||||||
|
|
||||||
fmt.Print(s.String())
|
// fmt.Print(s.String())
|
||||||
}
|
// }
|
||||||
|
|
||||||
func (d *Day13) Part1() string {
|
func (d *Day13) Part1() string {
|
||||||
outputStep := 0
|
outputStep := 0
|
||||||
@ -98,7 +97,7 @@ func (d *Day13) Part1() string {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return fmt.Sprintf("%d total tiles, # block tiles: %s%d%s", len(d.tiles), u.TextBold, d.getNumBlocks(), u.TextReset)
|
return fmt.Sprintf("# block tiles: %s%d%s (%d total tiles)", u.TextBold, d.getNumBlocks(), u.TextReset, len(d.tiles))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Day13) Part2() string {
|
func (d *Day13) Part2() string {
|
||||||
@ -135,7 +134,7 @@ func (d *Day13) Part2() string {
|
|||||||
ball = newTilePos
|
ball = newTilePos
|
||||||
} else if val == tileHPaddle {
|
} else if val == tileHPaddle {
|
||||||
paddle = newTilePos
|
paddle = newTilePos
|
||||||
// d.Draw()
|
// d.drawGameBoard()
|
||||||
// time.Sleep(time.Millisecond * 33)
|
// time.Sleep(time.Millisecond * 33)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
days/14.go
24
days/14.go
@ -104,10 +104,26 @@ func (d *Day14) Part1() string {
|
|||||||
func (d *Day14) Part2() string {
|
func (d *Day14) Part2() string {
|
||||||
oreAvailable := int64(1000000000000)
|
oreAvailable := int64(1000000000000)
|
||||||
estimate := oreAvailable / d.getOreRequiredForFuel(1)
|
estimate := oreAvailable / d.getOreRequiredForFuel(1)
|
||||||
lastSuccess := u.Bisect(estimate, estimate*2, 1, func(val int64) bool {
|
|
||||||
oreConsumed := d.getOreRequiredForFuel(val)
|
high := estimate * 2
|
||||||
return oreConsumed < oreAvailable
|
low := estimate
|
||||||
})
|
|
||||||
|
lastSuccess := low
|
||||||
|
lastFailure := high
|
||||||
|
fuelProduced := low
|
||||||
|
|
||||||
|
for math.Abs(float64(lastFailure-lastSuccess)) > 1 {
|
||||||
|
oreConsumed := d.getOreRequiredForFuel(fuelProduced)
|
||||||
|
adjustment := (lastFailure - lastSuccess) / 2
|
||||||
|
if oreConsumed < oreAvailable {
|
||||||
|
lastSuccess = fuelProduced
|
||||||
|
} else {
|
||||||
|
lastFailure = fuelProduced
|
||||||
|
adjustment = -adjustment
|
||||||
|
}
|
||||||
|
|
||||||
|
fuelProduced += adjustment
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("Maximum fuel we can make from 1 trillion ore: %s%d%s", u.TextBold, lastSuccess, u.TextReset)
|
return fmt.Sprintf("Maximum fuel we can make from 1 trillion ore: %s%d%s", u.TextBold, lastSuccess, u.TextReset)
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ func (d *Day15) Part1() string {
|
|||||||
visited.timesVisited = 1
|
visited.timesVisited = 1
|
||||||
}
|
}
|
||||||
d.pos = point{}
|
d.pos = point{}
|
||||||
// d.Draw()
|
d.Draw()
|
||||||
|
|
||||||
return fmt.Sprintf("Moves required to reach target: %s%d%s", u.TextBold, d.visited[d.goalPos].distanceFromStart, u.TextReset)
|
return fmt.Sprintf("Moves required to reach target: %s%d%s", u.TextBold, d.visited[d.goalPos].distanceFromStart, u.TextReset)
|
||||||
}
|
}
|
||||||
|
418
days/17.go
418
days/17.go
@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
type camViewCellType int
|
type camViewCellType int
|
||||||
type botFacing int
|
type botFacing int
|
||||||
type day17Grid [][]camViewCellType
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cellTypeScaffold camViewCellType = iota
|
cellTypeScaffold camViewCellType = iota
|
||||||
@ -28,9 +27,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
dirLeft = 1
|
dirLeft dirType = 1
|
||||||
dirRight = -1
|
dirRight dirType = -1
|
||||||
maxInstructionSetLength = 20
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -43,40 +41,33 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Day17 struct {
|
type Day17 struct {
|
||||||
program u.IntcodeProgram
|
program u.IntcodeProgram
|
||||||
|
grid [][]camViewCellType
|
||||||
|
botLocation u.Vec2i
|
||||||
|
botFacingDir botFacing
|
||||||
|
endLocation u.Vec2i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Day17) Parse() {
|
func (d *Day17) Parse() {
|
||||||
d.program = u.LoadIntcodeProgram("17p")
|
d.program = u.LoadIntcodeProgram("17p")
|
||||||
// d.program.SetDebugASCIIPrint(true)
|
d.grid = [][]camViewCellType{{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Day17) Num() int {
|
func (d Day17) Num() int {
|
||||||
return 17
|
return 17
|
||||||
}
|
}
|
||||||
|
|
||||||
func (currentDir botFacing) getNewFacingDir(turnDir int) botFacing {
|
func (d Day17) Draw() {
|
||||||
currentDir += botFacing(turnDir)
|
for y := range d.grid {
|
||||||
if currentDir < botFacingFirst {
|
for x := range d.grid[y] {
|
||||||
currentDir = botFacingLast
|
switch d.grid[y][x] {
|
||||||
} else if currentDir > botFacingLast {
|
|
||||||
currentDir = botFacingFirst
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentDir
|
|
||||||
}
|
|
||||||
|
|
||||||
func (grid day17Grid) Draw(botLocation u.Vec2i, botFacingDir botFacing, endLocation u.Vec2i) {
|
|
||||||
for y := range grid {
|
|
||||||
for x := range grid[y] {
|
|
||||||
switch grid[y][x] {
|
|
||||||
case cellTypeOpen:
|
case cellTypeOpen:
|
||||||
fmt.Print(" ")
|
fmt.Print(" ")
|
||||||
case cellTypeScaffold:
|
case cellTypeScaffold:
|
||||||
char := "█"
|
char := "█"
|
||||||
color := u.ColorBlack
|
color := u.ColorBlack
|
||||||
if botLocation.X == x && botLocation.Y == y {
|
if d.botLocation.X == x && d.botLocation.Y == y {
|
||||||
switch botFacingDir {
|
switch d.botFacingDir {
|
||||||
case botFacingUp:
|
case botFacingUp:
|
||||||
char = "^"
|
char = "^"
|
||||||
case botFacingLeft:
|
case botFacingLeft:
|
||||||
@ -86,7 +77,7 @@ func (grid day17Grid) Draw(botLocation u.Vec2i, botFacingDir botFacing, endLocat
|
|||||||
case botFacingRight:
|
case botFacingRight:
|
||||||
char = ">"
|
char = ">"
|
||||||
}
|
}
|
||||||
} else if endLocation.X == x && endLocation.Y == y {
|
} else if d.endLocation.X == x && d.endLocation.Y == y {
|
||||||
char = "@"
|
char = "@"
|
||||||
} else {
|
} else {
|
||||||
color = u.ColorWhite
|
color = u.ColorWhite
|
||||||
@ -98,17 +89,17 @@ func (grid day17Grid) Draw(botLocation u.Vec2i, botFacingDir botFacing, endLocat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grid day17Grid) getAdjacentScaffolds(y, x int) []u.Vec2i {
|
func (d Day17) getAdjacentScaffolds(y, x int) []u.Vec2i {
|
||||||
retval := make([]u.Vec2i, 0)
|
retval := make([]u.Vec2i, 0)
|
||||||
for _, offset := range day17AdjacentOffsets {
|
for _, offset := range day17AdjacentOffsets {
|
||||||
offY := y + offset.Y
|
offY := y + offset.Y
|
||||||
offX := x + offset.X
|
offX := x + offset.X
|
||||||
if offY < 0 || offY >= len(grid) ||
|
if offY < 0 || offY >= len(d.grid) ||
|
||||||
offX < 0 || offX >= len(grid[0]) {
|
offX < 0 || offX >= len(d.grid[0]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if grid[offY][offX] == cellTypeScaffold {
|
if d.grid[offY][offX] == cellTypeScaffold {
|
||||||
retval = append(retval, u.Vec2i{X: offX, Y: offY})
|
retval = append(retval, u.Vec2i{X: offX, Y: offY})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,40 +107,32 @@ func (grid day17Grid) getAdjacentScaffolds(y, x int) []u.Vec2i {
|
|||||||
return retval
|
return retval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grid day17Grid) forEachCellOfType(t camViewCellType, f func(y, x int)) {
|
func (d Day17) getNumSurroundingScaffolds(y, x int) int {
|
||||||
for y := range grid {
|
return len(d.getAdjacentScaffolds(y, x))
|
||||||
for x := range grid[y] {
|
}
|
||||||
if grid[y][x] == t {
|
|
||||||
|
func (d Day17) forEachCellOfType(t camViewCellType, f func(y, x int)) {
|
||||||
|
for y := range d.grid {
|
||||||
|
for x := range d.grid[y] {
|
||||||
|
if d.grid[y][x] == t {
|
||||||
f(y, x)
|
f(y, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grid *day17Grid) processGridUpdate(y int, rVal rune, currBotLocation u.Vec2i, currBotFacing botFacing) (int, u.Vec2i, botFacing) {
|
func (d Day17) getNewFacingDir(currentDir botFacing, turnDir dirType) botFacing {
|
||||||
grid.appendValue(rVal, y)
|
currentDir += botFacing(turnDir)
|
||||||
|
if currentDir < botFacingFirst {
|
||||||
switch rVal {
|
currentDir = botFacingLast
|
||||||
case '\n':
|
} else if currentDir > botFacingLast {
|
||||||
y++
|
currentDir = botFacingFirst
|
||||||
case '^', '<', 'v', '>':
|
|
||||||
currBotLocation = u.Vec2i{X: len((*grid)[y]) - 1, Y: y}
|
|
||||||
switch rVal {
|
|
||||||
case '^':
|
|
||||||
currBotFacing = botFacingUp
|
|
||||||
case '<':
|
|
||||||
currBotFacing = botFacingLeft
|
|
||||||
case 'v':
|
|
||||||
currBotFacing = botFacingDown
|
|
||||||
case '>':
|
|
||||||
currBotFacing = botFacingRight
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return y, currBotLocation, currBotFacing
|
return currentDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grid day17Grid) getCellTypeInDirection(y, x int, facingDir botFacing) (camViewCellType, int, int) {
|
func (d Day17) getCellTypeInDirection(y, x int, facingDir botFacing) (camViewCellType, int, int) {
|
||||||
newX := x
|
newX := x
|
||||||
newY := y
|
newY := y
|
||||||
switch facingDir {
|
switch facingDir {
|
||||||
@ -163,104 +146,144 @@ func (grid day17Grid) getCellTypeInDirection(y, x int, facingDir botFacing) (cam
|
|||||||
newX++
|
newX++
|
||||||
}
|
}
|
||||||
|
|
||||||
if newY < 0 || newY >= len(grid) || newX < 0 || newX >= len(grid[0]) {
|
if newY < 0 || newY >= len(d.grid) || newX < 0 || newX >= len(d.grid[0]) {
|
||||||
return cellTypeInvalid, newY, newX
|
return cellTypeInvalid, newY, newX
|
||||||
}
|
}
|
||||||
|
|
||||||
return grid[newY][newX], newY, newX
|
return d.grid[newY][newX], newY, newX
|
||||||
}
|
}
|
||||||
|
|
||||||
func (grid *day17Grid) appendValue(rVal rune, row int) {
|
func (d *Day17) Part1() string {
|
||||||
ensureCapacity := func(y int) {
|
y := 0
|
||||||
for len(*grid) <= y {
|
d.program.RunIn(func(inputStep int) int64 {
|
||||||
*grid = append(*grid, make([]camViewCellType, 0))
|
return 0
|
||||||
}
|
}, func(val int64, state u.IntcodeProgramState) {
|
||||||
}
|
rVal := rune(val)
|
||||||
|
switch rVal {
|
||||||
switch rVal {
|
case '\n':
|
||||||
case '#':
|
y++
|
||||||
ensureCapacity(row)
|
d.grid = append(d.grid, make([]camViewCellType, 0))
|
||||||
(*grid)[row] = append((*grid)[row], cellTypeScaffold)
|
case '#':
|
||||||
case '.':
|
d.grid[y] = append(d.grid[y], cellTypeScaffold)
|
||||||
ensureCapacity(row)
|
case '.':
|
||||||
(*grid)[row] = append((*grid)[row], cellTypeOpen)
|
d.grid[y] = append(d.grid[y], cellTypeOpen)
|
||||||
case '^', '<', 'v', '>':
|
case '^', '<', 'v', '>':
|
||||||
ensureCapacity(row)
|
d.botLocation = u.Vec2i{X: len(d.grid[y]), Y: y}
|
||||||
(*grid)[row] = append((*grid)[row], cellTypeScaffold)
|
d.grid[y] = append(d.grid[y], cellTypeScaffold)
|
||||||
}
|
switch rVal {
|
||||||
}
|
case '^':
|
||||||
|
d.botFacingDir = botFacingUp
|
||||||
func (grid day17Grid) findEndLocation(botLocation u.Vec2i) u.Vec2i {
|
case '<':
|
||||||
var endLocation u.Vec2i
|
d.botFacingDir = botFacingLeft
|
||||||
grid.forEachCellOfType(cellTypeScaffold, func(y, x int) {
|
case 'v':
|
||||||
if numSurrounding := len(grid.getAdjacentScaffolds(y, x)); numSurrounding == 1 {
|
d.botFacingDir = botFacingDown
|
||||||
if botLocation.X != x || botLocation.Y != y {
|
case '>':
|
||||||
endLocation = u.Vec2i{X: x, Y: y}
|
d.botFacingDir = botFacingRight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return endLocation
|
for y := len(d.grid) - 1; y >= 0; y-- {
|
||||||
}
|
if len(d.grid[y]) == 0 {
|
||||||
|
d.grid = d.grid[0 : len(d.grid)-1]
|
||||||
func (grid day17Grid) getTurnDirectionFromCorner(pos u.Vec2i, botFacingDir botFacing) (int, string) {
|
|
||||||
adj := grid.getAdjacentScaffolds(pos.Y, pos.X)
|
|
||||||
turnDirection := 0
|
|
||||||
// this is so awful. i'm sure there's a better way, but i'm tired.
|
|
||||||
if botFacingDir == botFacingUp || botFacingDir == botFacingDown {
|
|
||||||
if u.ArrayContains(adj, u.Vec2i{X: pos.X - 1, Y: pos.Y}) {
|
|
||||||
if botFacingDir == botFacingUp {
|
|
||||||
turnDirection = dirLeft
|
|
||||||
} else if botFacingDir == botFacingDown {
|
|
||||||
turnDirection = dirRight
|
|
||||||
}
|
|
||||||
} else if u.ArrayContains(adj, u.Vec2i{X: pos.X + 1, Y: pos.Y}) {
|
|
||||||
if botFacingDir == botFacingUp {
|
|
||||||
turnDirection = dirRight
|
|
||||||
} else if botFacingDir == botFacingDown {
|
|
||||||
turnDirection = dirLeft
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if u.ArrayContains(adj, u.Vec2i{X: pos.X, Y: pos.Y - 1}) {
|
|
||||||
if botFacingDir == botFacingLeft {
|
|
||||||
turnDirection = dirRight
|
|
||||||
} else if botFacingDir == botFacingRight {
|
|
||||||
turnDirection = dirLeft
|
|
||||||
}
|
|
||||||
} else if u.ArrayContains(adj, u.Vec2i{X: pos.X, Y: pos.Y + 1}) {
|
|
||||||
if botFacingDir == botFacingLeft {
|
|
||||||
turnDirection = dirLeft
|
|
||||||
} else if botFacingDir == botFacingRight {
|
|
||||||
turnDirection = dirRight
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirAscii := "L"
|
alignmentParameterTotal := 0
|
||||||
if turnDirection == dirRight {
|
d.forEachCellOfType(cellTypeScaffold, func(y, x int) {
|
||||||
dirAscii = "R"
|
if numSurrounding := d.getNumSurroundingScaffolds(y, x); numSurrounding == 4 {
|
||||||
}
|
alignmentParameterTotal += y * x
|
||||||
|
} else if numSurrounding == 1 {
|
||||||
|
if d.botLocation.X != x || d.botLocation.Y != y {
|
||||||
|
d.endLocation = u.Vec2i{X: x, Y: y}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return turnDirection, dirAscii
|
// d.Draw()
|
||||||
|
|
||||||
|
return fmt.Sprintf("Alignment parameter sum: %s%d%s", u.TextBold, alignmentParameterTotal, u.TextReset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildInstructionString(instructions []string) string {
|
func (d *Day17) Part2() string {
|
||||||
|
instructions := make([]string, 0)
|
||||||
|
|
||||||
|
pos := d.botLocation
|
||||||
|
botFacingDir := d.botFacingDir
|
||||||
|
for {
|
||||||
|
if pos == d.endLocation {
|
||||||
|
fmt.Println()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
adj := d.getAdjacentScaffolds(pos.Y, pos.X)
|
||||||
|
turnDirection := dirType(0)
|
||||||
|
if botFacingDir == botFacingUp || botFacingDir == botFacingDown {
|
||||||
|
if u.ArrayContains(adj, u.Vec2i{X: pos.X - 1, Y: pos.Y}) {
|
||||||
|
if botFacingDir == botFacingUp {
|
||||||
|
turnDirection = dirLeft
|
||||||
|
} else if botFacingDir == botFacingDown {
|
||||||
|
turnDirection = dirRight
|
||||||
|
}
|
||||||
|
} else if u.ArrayContains(adj, u.Vec2i{X: pos.X + 1, Y: pos.Y}) {
|
||||||
|
if botFacingDir == botFacingUp {
|
||||||
|
turnDirection = dirRight
|
||||||
|
} else if botFacingDir == botFacingDown {
|
||||||
|
turnDirection = dirLeft
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if u.ArrayContains(adj, u.Vec2i{X: pos.X, Y: pos.Y - 1}) {
|
||||||
|
if botFacingDir == botFacingLeft {
|
||||||
|
turnDirection = dirRight
|
||||||
|
} else if botFacingDir == botFacingRight {
|
||||||
|
turnDirection = dirLeft
|
||||||
|
}
|
||||||
|
} else if u.ArrayContains(adj, u.Vec2i{X: pos.X, Y: pos.Y + 1}) {
|
||||||
|
if botFacingDir == botFacingLeft {
|
||||||
|
turnDirection = dirLeft
|
||||||
|
} else if botFacingDir == botFacingRight {
|
||||||
|
turnDirection = dirRight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if turnDirection == 0 {
|
||||||
|
panic("at an invalid location somehow")
|
||||||
|
}
|
||||||
|
|
||||||
|
dirAscii := "L"
|
||||||
|
if turnDirection == dirRight {
|
||||||
|
dirAscii = "R"
|
||||||
|
}
|
||||||
|
instructions = append(instructions, dirAscii)
|
||||||
|
|
||||||
|
botFacingDir = d.getNewFacingDir(botFacingDir, turnDirection)
|
||||||
|
numMoved := 0
|
||||||
|
for {
|
||||||
|
cell, newY, newX := d.getCellTypeInDirection(pos.Y, pos.X, botFacingDir)
|
||||||
|
if cell != cellTypeScaffold {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
pos.X = newX
|
||||||
|
pos.Y = newY
|
||||||
|
numMoved++
|
||||||
|
}
|
||||||
|
instructions = append(instructions, fmt.Sprintf("%d", numMoved))
|
||||||
|
}
|
||||||
|
|
||||||
workingInstructions := make([]string, len(instructions))
|
workingInstructions := make([]string, len(instructions))
|
||||||
copy(workingInstructions, instructions)
|
copy(workingInstructions, instructions)
|
||||||
|
|
||||||
minimumRecurrence := 3
|
|
||||||
initialInstructionSubsetLen := 4
|
|
||||||
|
|
||||||
instructionStr := strings.Join(workingInstructions, ",")
|
instructionStr := strings.Join(workingInstructions, ",")
|
||||||
progs := make([][]string, 3)
|
progs := make([][]string, 3)
|
||||||
for i := range progs {
|
for i := 0; i < 3; i++ {
|
||||||
numFound := minimumRecurrence
|
numFound := 3
|
||||||
subLen := initialInstructionSubsetLen
|
subLen := 4
|
||||||
for numFound >= minimumRecurrence {
|
for numFound >= 3 {
|
||||||
numFound = 1
|
numFound = 1
|
||||||
instructionSubset := strings.Join(workingInstructions[0:subLen], ",")
|
instructionSubset := strings.Join(workingInstructions[0:subLen], ",")
|
||||||
if len(instructionSubset) > maxInstructionSetLength {
|
if len(instructionSubset) > 20 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for x := len(instructionSubset); x <= len(instructionStr)-len(instructionSubset); x++ {
|
for x := len(instructionSubset); x <= len(instructionStr)-len(instructionSubset); x++ {
|
||||||
@ -269,11 +292,11 @@ func buildInstructionString(instructions []string) string {
|
|||||||
x += len(instructionSubset)
|
x += len(instructionSubset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if numFound >= minimumRecurrence {
|
if numFound >= 3 {
|
||||||
subLen += 2
|
subLen += 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if numFound < minimumRecurrence {
|
if numFound < 3 {
|
||||||
subLen -= 2
|
subLen -= 2
|
||||||
}
|
}
|
||||||
progs[i] = make([]string, subLen)
|
progs[i] = make([]string, subLen)
|
||||||
@ -290,133 +313,28 @@ func buildInstructionString(instructions []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if workingInstructions != nil {
|
if workingInstructions != nil {
|
||||||
panic("failed to use up all instructions")
|
panic("didn't empty instructions")
|
||||||
}
|
}
|
||||||
|
instructionStr = strings.Join(instructions, ",")
|
||||||
|
instructionStr = strings.ReplaceAll(instructionStr, strings.Join(progs[0], ","), "A")
|
||||||
|
instructionStr = strings.ReplaceAll(instructionStr, strings.Join(progs[1], ","), "B")
|
||||||
|
instructionStr = strings.ReplaceAll(instructionStr, strings.Join(progs[2], ","), "C")
|
||||||
|
|
||||||
programStr := strings.Join(instructions, ",")
|
instructionStr = fmt.Sprintf("%s\n%s\n%s\n%s\nn\n",
|
||||||
for i := range progs {
|
instructionStr,
|
||||||
programStr = strings.ReplaceAll(programStr, strings.Join(progs[i], ","), fmt.Sprintf("%c", 'A'+i))
|
strings.Join(progs[0], ","),
|
||||||
}
|
strings.Join(progs[1], ","),
|
||||||
|
strings.Join(progs[2], ","),
|
||||||
sb := strings.Builder{}
|
)
|
||||||
sb.WriteString(programStr)
|
|
||||||
sb.WriteRune('\n')
|
|
||||||
|
|
||||||
for i := range progs {
|
|
||||||
sb.WriteString(strings.Join(progs[i], ","))
|
|
||||||
sb.WriteRune('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
runDebug := 'n'
|
|
||||||
sb.WriteRune(runDebug)
|
|
||||||
sb.WriteRune('\n')
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (grid day17Grid) solvePath(botLocation u.Vec2i, botFacingDir botFacing) string {
|
|
||||||
instructions := make([]string, 0)
|
|
||||||
|
|
||||||
pos := botLocation
|
|
||||||
endLocation := grid.findEndLocation(botLocation)
|
|
||||||
for {
|
|
||||||
if pos == endLocation {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
turnDirection, dirAscii := grid.getTurnDirectionFromCorner(pos, botFacingDir)
|
|
||||||
if turnDirection == 0 {
|
|
||||||
panic("at an invalid location somehow")
|
|
||||||
}
|
|
||||||
|
|
||||||
instructions = append(instructions, dirAscii)
|
|
||||||
|
|
||||||
botFacingDir = botFacingDir.getNewFacingDir(turnDirection)
|
|
||||||
numMoved := 0
|
|
||||||
for {
|
|
||||||
cell, newY, newX := grid.getCellTypeInDirection(pos.Y, pos.X, botFacingDir)
|
|
||||||
if cell != cellTypeScaffold {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
pos.X = newX
|
|
||||||
pos.Y = newY
|
|
||||||
numMoved++
|
|
||||||
}
|
|
||||||
instructions = append(instructions, fmt.Sprintf("%d", numMoved))
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildInstructionString(instructions)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day17) Part1() string {
|
|
||||||
grid := day17Grid{}
|
|
||||||
y := 0
|
|
||||||
var botLocation u.Vec2i
|
|
||||||
var botFacingDir botFacing
|
|
||||||
|
|
||||||
d.program.RunIn(func(inputStep int) int64 {
|
|
||||||
return 0
|
|
||||||
}, func(val int64, state u.IntcodeProgramState) {
|
|
||||||
rVal := rune(val)
|
|
||||||
y, botLocation, botFacingDir = grid.processGridUpdate(y, rVal, botLocation, botFacingDir)
|
|
||||||
})
|
|
||||||
|
|
||||||
alignmentParameterTotal := 0
|
|
||||||
grid.forEachCellOfType(cellTypeScaffold, func(y, x int) {
|
|
||||||
if numSurrounding := len(grid.getAdjacentScaffolds(y, x)); numSurrounding == 4 {
|
|
||||||
alignmentParameterTotal += y * x
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// endLocation := grid.findEndLocation(botLocation)
|
|
||||||
// grid.Draw(botLocation, botFacingDir, endLocation)
|
|
||||||
|
|
||||||
return fmt.Sprintf("Alignment parameter sum: %s%d%s", u.TextBold, alignmentParameterTotal, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day17) Part2() string {
|
|
||||||
beforeGrid := day17Grid{}
|
|
||||||
var beforeBotLocation u.Vec2i
|
|
||||||
var beforeBotFacing botFacing
|
|
||||||
|
|
||||||
afterGrid := day17Grid{}
|
|
||||||
var afterBotLocation u.Vec2i
|
|
||||||
var afterBotFacing botFacing
|
|
||||||
|
|
||||||
d.program.Reset()
|
d.program.Reset()
|
||||||
d.program.SetMemory(0, 2)
|
d.program.SetMemory(0, 2)
|
||||||
|
dustCollected := int64(0)
|
||||||
row := 0
|
|
||||||
var outputState int
|
|
||||||
var lastOutput int64
|
|
||||||
d.program.RunIn(func(inputStep int) int64 {
|
d.program.RunIn(func(inputStep int) int64 {
|
||||||
panic("unexpected read")
|
return int64(instructionStr[inputStep-1])
|
||||||
}, func(val int64, state u.IntcodeProgramState) {
|
}, func(val int64, state u.IntcodeProgramState) {
|
||||||
rVal := rune(val)
|
dustCollected = val
|
||||||
if outputState == 0 {
|
|
||||||
row, beforeBotLocation, beforeBotFacing = beforeGrid.processGridUpdate(row, rVal, beforeBotLocation, beforeBotFacing)
|
|
||||||
} else if outputState == 2 {
|
|
||||||
row, afterBotLocation, afterBotFacing = afterGrid.processGridUpdate(row, rVal, afterBotLocation, afterBotFacing)
|
|
||||||
}
|
|
||||||
|
|
||||||
if rVal == '\n' && lastOutput == '\n' {
|
|
||||||
if outputState == 0 {
|
|
||||||
d.program.FeedInputString(beforeGrid.solvePath(beforeBotLocation, beforeBotFacing))
|
|
||||||
}
|
|
||||||
outputState++
|
|
||||||
row = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
lastOutput = val
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// fmt.Println("initial grid:")
|
return fmt.Sprintf("Dust collected after traveling all paths: %s%d%s", u.TextBold, dustCollected, u.TextReset)
|
||||||
// beforeEndLocation := beforeGrid.findEndLocation(beforeBotLocation)
|
|
||||||
// beforeGrid.Draw(beforeBotLocation, beforeBotFacing, beforeEndLocation)
|
|
||||||
|
|
||||||
// fmt.Println("completed grid:")
|
|
||||||
// afterEndLocation := afterGrid.findEndLocation(afterBotLocation)
|
|
||||||
// afterGrid.Draw(afterBotLocation, afterBotFacing, afterEndLocation)
|
|
||||||
|
|
||||||
return fmt.Sprintf("Dust collected after traveling all paths: %s%d%s", u.TextBold, lastOutput, u.TextReset)
|
|
||||||
}
|
}
|
||||||
|
345
days/18.go
345
days/18.go
@ -1,345 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"container/heap"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type day18Cell int
|
|
||||||
type day18Vec u.Vec2[int]
|
|
||||||
type day18Graph map[rune][]u.Pair[rune, int]
|
|
||||||
|
|
||||||
const (
|
|
||||||
day18CellWall day18Cell = iota
|
|
||||||
day18CellOpen
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
day18AdjacentOffsets = []day18Vec{
|
|
||||||
{X: -1, Y: 0},
|
|
||||||
{X: 1, Y: 0},
|
|
||||||
{X: 0, Y: -1},
|
|
||||||
{X: 0, Y: 1},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type reachableKeysMemo struct {
|
|
||||||
pos rune
|
|
||||||
keysFound int
|
|
||||||
}
|
|
||||||
|
|
||||||
type minStepsMemo struct {
|
|
||||||
pos string
|
|
||||||
keysToFind int
|
|
||||||
keysFound int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Day18 struct {
|
|
||||||
entrance day18Vec
|
|
||||||
grid [][]day18Cell
|
|
||||||
doors map[day18Vec]int
|
|
||||||
keys map[day18Vec]int
|
|
||||||
knownReachableKeys map[reachableKeysMemo][]u.Pair[rune, int]
|
|
||||||
knownMinimumSteps map[minStepsMemo]int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day18) Parse() {
|
|
||||||
d.doors = make(map[day18Vec]int)
|
|
||||||
d.keys = make(map[day18Vec]int)
|
|
||||||
d.knownReachableKeys = make(map[reachableKeysMemo][]u.Pair[rune, int])
|
|
||||||
d.knownMinimumSteps = make(map[minStepsMemo]int, 0)
|
|
||||||
|
|
||||||
lines := u.GetStringLines("18p")
|
|
||||||
d.grid = make([][]day18Cell, len(lines))
|
|
||||||
for i, line := range lines {
|
|
||||||
d.grid[i] = make([]day18Cell, len(line))
|
|
||||||
for j, char := range line {
|
|
||||||
if char == '#' {
|
|
||||||
d.grid[i][j] = day18CellWall
|
|
||||||
} else if char == '.' {
|
|
||||||
d.grid[i][j] = day18CellOpen
|
|
||||||
} else if char == '@' {
|
|
||||||
d.grid[i][j] = day18CellOpen
|
|
||||||
d.entrance = day18Vec{X: j, Y: i}
|
|
||||||
} else if char >= 'A' && char <= 'Z' {
|
|
||||||
d.grid[i][j] = day18CellOpen
|
|
||||||
d.doors[day18Vec{X: j, Y: i}] = int(char - 'A')
|
|
||||||
} else if char >= 'a' && char <= 'z' {
|
|
||||||
d.grid[i][j] = day18CellOpen
|
|
||||||
d.keys[day18Vec{X: j, Y: i}] = int(char - 'a')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) Num() int {
|
|
||||||
return 18
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) Draw(grid [][]day18Cell, keys, doors map[day18Vec]int, entrances ...day18Vec) {
|
|
||||||
for y := range grid {
|
|
||||||
for x := range grid[y] {
|
|
||||||
switch grid[y][x] {
|
|
||||||
case day18CellWall:
|
|
||||||
fmt.Print("█")
|
|
||||||
case day18CellOpen:
|
|
||||||
posVec := day18Vec{X: x, Y: y}
|
|
||||||
if _, exists := doors[posVec]; exists {
|
|
||||||
fmt.Printf("%c", rune(doors[posVec]+'A'))
|
|
||||||
} else if _, exists := keys[posVec]; exists {
|
|
||||||
fmt.Printf("%c", rune(keys[posVec]+'a'))
|
|
||||||
} else if u.ArrayContains(entrances, posVec) {
|
|
||||||
fmt.Print("@")
|
|
||||||
} else {
|
|
||||||
fmt.Print(".")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) findAdjacentCells(inPos day18Vec, keys, doors map[day18Vec]int, grid [][]day18Cell) []u.Pair[rune, int] {
|
|
||||||
found := make([]u.Pair[rune, int], 0)
|
|
||||||
|
|
||||||
getAdjacent := func(pos day18Vec) []day18Vec {
|
|
||||||
retAdjacent := make([]day18Vec, 0, len(day18AdjacentOffsets))
|
|
||||||
for _, off := range day18AdjacentOffsets {
|
|
||||||
offVec := day18Vec{X: pos.X + off.X, Y: pos.Y + off.Y}
|
|
||||||
if grid[offVec.Y][offVec.X] == day18CellWall {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
retAdjacent = append(retAdjacent, offVec)
|
|
||||||
}
|
|
||||||
|
|
||||||
return retAdjacent
|
|
||||||
}
|
|
||||||
|
|
||||||
queue := make([]u.Pair[int, day18Vec], 0)
|
|
||||||
visited := make(map[day18Vec]bool)
|
|
||||||
for _, adjacent := range getAdjacent(inPos) {
|
|
||||||
queue = append(queue, u.Pair[int, day18Vec]{First: 1, Second: adjacent})
|
|
||||||
}
|
|
||||||
|
|
||||||
for len(queue) > 0 {
|
|
||||||
next := queue[0]
|
|
||||||
queue = queue[1:]
|
|
||||||
|
|
||||||
if _, exists := visited[next.Second]; !exists {
|
|
||||||
visited[next.Second] = true
|
|
||||||
|
|
||||||
key, adjacentIsKey := keys[next.Second]
|
|
||||||
door, adjacentIsDoor := doors[next.Second]
|
|
||||||
if adjacentIsKey || adjacentIsDoor {
|
|
||||||
var rVal rune
|
|
||||||
if adjacentIsKey {
|
|
||||||
rVal = rune('a' + key)
|
|
||||||
} else if adjacentIsDoor {
|
|
||||||
rVal = rune('A' + door)
|
|
||||||
}
|
|
||||||
|
|
||||||
alreadyFound := false
|
|
||||||
for _, p := range found {
|
|
||||||
if p.First == rVal {
|
|
||||||
alreadyFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !alreadyFound {
|
|
||||||
found = append(found, u.Pair[rune, int]{First: rVal, Second: next.First})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, neighbor := range getAdjacent(next.Second) {
|
|
||||||
if _, exists := visited[neighbor]; !exists {
|
|
||||||
queue = append(queue, u.Pair[int, day18Vec]{First: next.First + 1, Second: neighbor})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return found
|
|
||||||
}
|
|
||||||
|
|
||||||
type day18PriorityQueue struct {
|
|
||||||
distance int
|
|
||||||
neighbor rune
|
|
||||||
}
|
|
||||||
type day18PriorityQueueHeap []day18PriorityQueue
|
|
||||||
|
|
||||||
func (h day18PriorityQueueHeap) Len() int { return len(h) }
|
|
||||||
func (h day18PriorityQueueHeap) Less(i, j int) bool { return h[i].distance < h[j].distance }
|
|
||||||
func (h day18PriorityQueueHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
|
||||||
|
|
||||||
func (h *day18PriorityQueueHeap) Push(x any) {
|
|
||||||
*h = append(*h, x.(day18PriorityQueue))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *day18PriorityQueueHeap) Pop() any {
|
|
||||||
old := *h
|
|
||||||
n := len(old)
|
|
||||||
x := old[n-1]
|
|
||||||
*h = old[0 : n-1]
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) reachableKeys(inPos rune, keysFound int, graph day18Graph) []u.Pair[rune, int] {
|
|
||||||
memo := reachableKeysMemo{
|
|
||||||
pos: inPos,
|
|
||||||
keysFound: keysFound,
|
|
||||||
}
|
|
||||||
if v, exists := d.knownReachableKeys[memo]; exists {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
ret := make([]u.Pair[rune, int], 0)
|
|
||||||
distance := make(map[rune]int)
|
|
||||||
|
|
||||||
ih := make(day18PriorityQueueHeap, 0)
|
|
||||||
|
|
||||||
for _, p := range graph[inPos] {
|
|
||||||
ih = append(ih, day18PriorityQueue{
|
|
||||||
distance: p.Second,
|
|
||||||
neighbor: p.First,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
heap.Init(&ih)
|
|
||||||
|
|
||||||
for ih.Len() > 0 {
|
|
||||||
node := heap.Pop(&ih).(day18PriorityQueue)
|
|
||||||
|
|
||||||
// it's a key and we haven't picked it up yet...
|
|
||||||
if node.neighbor >= 'a' && node.neighbor <= 'z' && (1<<int(node.neighbor-'a')&keysFound) == 0 {
|
|
||||||
ret = append(ret, u.Pair[rune, int]{First: node.neighbor, Second: node.distance})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// it's a door but we don't have the key yet...
|
|
||||||
if node.neighbor >= 'A' && node.neighbor <= 'Z' && ((1<<int(node.neighbor-'A'))&keysFound) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range graph[node.neighbor] {
|
|
||||||
newDistance := node.distance + p.Second
|
|
||||||
if dist, exists := distance[p.First]; !exists || newDistance < dist {
|
|
||||||
distance[p.First] = newDistance
|
|
||||||
heap.Push(&ih, day18PriorityQueue{
|
|
||||||
distance: newDistance,
|
|
||||||
neighbor: p.First,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
d.knownReachableKeys[memo] = ret
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) minimumSteps(inPos string, keysToFind int, keysFound int, graph day18Graph) int {
|
|
||||||
memo := minStepsMemo{
|
|
||||||
pos: inPos,
|
|
||||||
keysToFind: keysToFind,
|
|
||||||
keysFound: keysFound,
|
|
||||||
}
|
|
||||||
if v, exists := d.knownMinimumSteps[memo]; exists {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
if keysToFind == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
best := math.Inf(1)
|
|
||||||
for _, item := range inPos {
|
|
||||||
for _, p := range d.reachableKeys(item, keysFound, graph) {
|
|
||||||
sb := strings.Builder{}
|
|
||||||
oldIdx := strings.IndexRune(inPos, item)
|
|
||||||
for i := range inPos {
|
|
||||||
if i == oldIdx {
|
|
||||||
sb.WriteRune(p.First)
|
|
||||||
} else {
|
|
||||||
sb.WriteByte(inPos[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newKeys := keysFound + (1 << (p.First - 'a'))
|
|
||||||
dist := p.Second
|
|
||||||
|
|
||||||
dist += d.minimumSteps(sb.String(), keysToFind-1, newKeys, graph)
|
|
||||||
|
|
||||||
if float64(dist) < best {
|
|
||||||
best = float64(dist)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
d.knownMinimumSteps[memo] = int(best)
|
|
||||||
return int(best)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) buildGraph(pos []day18Vec, keys map[day18Vec]int, doors map[day18Vec]int, grid [][]day18Cell) day18Graph {
|
|
||||||
graph := make(day18Graph)
|
|
||||||
for i, p := range pos {
|
|
||||||
adjacent := d.findAdjacentCells(p, keys, doors, grid)
|
|
||||||
graph[rune('1'+i)] = adjacent
|
|
||||||
}
|
|
||||||
for keyPos, keyType := range keys {
|
|
||||||
graph[rune('a'+keyType)] = d.findAdjacentCells(keyPos, keys, doors, grid)
|
|
||||||
}
|
|
||||||
for doorPos, doorType := range doors {
|
|
||||||
graph[rune('A'+doorType)] = d.findAdjacentCells(doorPos, keys, doors, grid)
|
|
||||||
}
|
|
||||||
|
|
||||||
return graph
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day18) part2PatchMap(grid [][]day18Cell, entrance day18Vec) []day18Vec {
|
|
||||||
grid[entrance.Y-1][entrance.X] = day18CellWall
|
|
||||||
grid[entrance.Y][entrance.X-1] = day18CellWall
|
|
||||||
grid[entrance.Y][entrance.X] = day18CellWall
|
|
||||||
grid[entrance.Y][entrance.X+1] = day18CellWall
|
|
||||||
grid[entrance.Y+1][entrance.X] = day18CellWall
|
|
||||||
|
|
||||||
return []day18Vec{
|
|
||||||
{X: entrance.X - 1, Y: entrance.Y - 1},
|
|
||||||
{X: entrance.X + 1, Y: entrance.Y - 1},
|
|
||||||
{X: entrance.X - 1, Y: entrance.Y + 1},
|
|
||||||
{X: entrance.X + 1, Y: entrance.Y + 1},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day18) Part1() string {
|
|
||||||
// fmt.Println("initial state:")
|
|
||||||
// d.Draw(d.grid, d.keys, d.doors, d.entrance)
|
|
||||||
|
|
||||||
graph := d.buildGraph([]day18Vec{d.entrance}, d.keys, d.doors, d.grid)
|
|
||||||
minSteps := d.minimumSteps("1", len(d.keys), 0, graph)
|
|
||||||
|
|
||||||
return fmt.Sprintf("Total distance traveled: %s%d%s", u.TextBold, minSteps, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day18) Part2() string {
|
|
||||||
// fmt.Println("initial state:")
|
|
||||||
grid := make([][]day18Cell, len(d.grid))
|
|
||||||
for i := range d.grid {
|
|
||||||
grid[i] = make([]day18Cell, len(d.grid[i]))
|
|
||||||
copy(grid[i], d.grid[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
entrances := d.part2PatchMap(grid, d.entrance)
|
|
||||||
// d.Draw(grid, d.keys, d.doors, entrances...)
|
|
||||||
|
|
||||||
// clear memoized maps that (might have) came from part1
|
|
||||||
d.knownMinimumSteps = make(map[minStepsMemo]int)
|
|
||||||
d.knownReachableKeys = make(map[reachableKeysMemo][]u.Pair[rune, int])
|
|
||||||
|
|
||||||
graph := d.buildGraph(entrances, d.keys, d.doors, grid)
|
|
||||||
minSteps := d.minimumSteps("1234", len(d.keys), 0, graph)
|
|
||||||
|
|
||||||
return fmt.Sprintf("Total distance traveled: %s%d%s", u.TextBold, minSteps, u.TextReset)
|
|
||||||
}
|
|
146
days/19.go
146
days/19.go
@ -1,146 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Day19 struct {
|
|
||||||
program u.IntcodeProgram
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day19) Parse() {
|
|
||||||
d.program = u.LoadIntcodeProgram("19p")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day19) Num() int {
|
|
||||||
return 19
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day19) Part1() string {
|
|
||||||
grid := make([][]bool, 50)
|
|
||||||
for y := 0; y < len(grid); y++ {
|
|
||||||
grid[y] = make([]bool, 50)
|
|
||||||
}
|
|
||||||
|
|
||||||
count := int64(0)
|
|
||||||
|
|
||||||
for y := 0; y < 50; y++ {
|
|
||||||
for x := 0; x < 50; x++ {
|
|
||||||
d.program.Reset()
|
|
||||||
d.program.RunIn(func(inputStep int) int64 {
|
|
||||||
if inputStep == 1 {
|
|
||||||
return int64(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
return int64(y)
|
|
||||||
}, func(val int64, state u.IntcodeProgramState) {
|
|
||||||
res := val == 1
|
|
||||||
grid[y][x] = res
|
|
||||||
if res {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Println("50x50 tractor view:")
|
|
||||||
// for y := 0; y < len(grid); y++ {
|
|
||||||
// for x := 0; x < len(grid[y]); x++ {
|
|
||||||
// if grid[y][x] {
|
|
||||||
// fmt.Print("█")
|
|
||||||
// } else {
|
|
||||||
// fmt.Print(" ")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// fmt.Println()
|
|
||||||
// }
|
|
||||||
|
|
||||||
return fmt.Sprintf("Points affected in 50x50 area: %s%d%s", u.TextBold, count, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day19) Part2() string {
|
|
||||||
f := func(x, y int) bool {
|
|
||||||
ret := false
|
|
||||||
d.program.Reset()
|
|
||||||
d.program.RunIn(func(inputStep int) int64 {
|
|
||||||
if inputStep == 1 {
|
|
||||||
return int64(x)
|
|
||||||
}
|
|
||||||
return int64(y)
|
|
||||||
}, func(val int64, state u.IntcodeProgramState) {
|
|
||||||
ret = val == 1
|
|
||||||
})
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
// find lower bound
|
|
||||||
// this may not be necessary, but helps seed the bisect with a known-good lower bound
|
|
||||||
startY := 0
|
|
||||||
startX := 0
|
|
||||||
for y := 1; startY == 0; y++ {
|
|
||||||
for x := 0; x < 10*y; x++ {
|
|
||||||
if f(x, y) {
|
|
||||||
startY = y
|
|
||||||
startX = x
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastGoodX := 0
|
|
||||||
threshold := 1
|
|
||||||
// add 100 to start y since we know it has to be a 100x100 square.
|
|
||||||
// since we multiply x by 10,000 for the final result, that tells us y cannot be 10k+
|
|
||||||
y := u.Bisect(startY+100, 9999, threshold, func(y int) bool {
|
|
||||||
foundX := false
|
|
||||||
for x := startX; ; x++ {
|
|
||||||
// check top left
|
|
||||||
if !f(x, y) {
|
|
||||||
if !foundX {
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundX {
|
|
||||||
foundX = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// check top right
|
|
||||||
if !f(x+99, y) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// check bottom left
|
|
||||||
if !f(x, y+99) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// we believe the corners work, so run final validations on the full borders.
|
|
||||||
// this may not be necessary, but i've seen some rows end up shorter than a
|
|
||||||
// previous row because of the angle of the beam and our integer fidelity.
|
|
||||||
// plus it's really not that much more expensive to do to be certain we're correct.
|
|
||||||
for y2 := y; y2 < y+100; y2++ {
|
|
||||||
// right wall
|
|
||||||
if !f(x+99, y2) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
// left wall
|
|
||||||
if !f(x, y2) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastGoodX = x
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// since we invert our bisect success returns, we need to increment y to
|
|
||||||
// tip back over into the "success" range
|
|
||||||
y += threshold
|
|
||||||
result := (lastGoodX * 10000) + y
|
|
||||||
return fmt.Sprintf("Closest 100x100 square for the ship starts at %d,%d = %s%d%s", lastGoodX, y, u.TextBold, result, u.TextReset)
|
|
||||||
}
|
|
398
days/20.go
398
days/20.go
@ -1,398 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"container/heap"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type day20Cell int8
|
|
||||||
type day20Graph map[day20Portal][]u.Pair[day20Portal, int]
|
|
||||||
|
|
||||||
const (
|
|
||||||
day20CellWall day20Cell = iota
|
|
||||||
day20CellPath
|
|
||||||
day20CellDonutHole
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
day20AdjacentOffsets = []u.Vec2i{
|
|
||||||
{X: -1, Y: 0},
|
|
||||||
{X: 1, Y: 0},
|
|
||||||
{X: 0, Y: -1},
|
|
||||||
{X: 0, Y: 1},
|
|
||||||
}
|
|
||||||
|
|
||||||
entrancePortal = day20Portal{name: "AA"}
|
|
||||||
exitPortal = day20Portal{name: "ZZ"}
|
|
||||||
)
|
|
||||||
|
|
||||||
type day20Portal struct {
|
|
||||||
name string
|
|
||||||
inner bool
|
|
||||||
depth int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Day20 struct {
|
|
||||||
grid [][]day20Cell
|
|
||||||
entrance u.Vec2i
|
|
||||||
exit u.Vec2i
|
|
||||||
portals map[day20Portal]u.Vec2i
|
|
||||||
portalNames []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day20) Parse() {
|
|
||||||
d.portals = make(map[day20Portal]u.Vec2i)
|
|
||||||
d.portalNames = make([]string, 0)
|
|
||||||
|
|
||||||
lines := u.GetStringLines("20p")
|
|
||||||
d.grid = make([][]day20Cell, len(lines)-4)
|
|
||||||
currPortal := strings.Builder{}
|
|
||||||
|
|
||||||
for row, line := range lines {
|
|
||||||
y := row - 2
|
|
||||||
isGridRow := row >= 2 && row < len(lines)-2
|
|
||||||
|
|
||||||
if isGridRow {
|
|
||||||
d.grid[y] = make([]day20Cell, len(line)-4)
|
|
||||||
}
|
|
||||||
|
|
||||||
for col, ch := range lines[row] {
|
|
||||||
x := col - 2
|
|
||||||
isGridCol := col >= 2 && col < len(line)-2
|
|
||||||
|
|
||||||
if isGridRow && isGridCol {
|
|
||||||
if ch == '#' {
|
|
||||||
d.grid[y][x] = day20CellWall
|
|
||||||
} else if ch == '.' {
|
|
||||||
d.grid[y][x] = day20CellPath
|
|
||||||
} else {
|
|
||||||
d.grid[y][x] = day20CellDonutHole
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ch >= 'A' && ch <= 'Z' {
|
|
||||||
portalX := 0
|
|
||||||
portalY := 0
|
|
||||||
if len(line) > col+1 && line[col+1] >= 'A' && line[col+1] <= 'Z' {
|
|
||||||
currPortal.WriteRune(ch)
|
|
||||||
currPortal.WriteRune(rune(line[col+1]))
|
|
||||||
|
|
||||||
if len(line) > col+2 && line[col+2] == '.' {
|
|
||||||
portalY = y
|
|
||||||
portalX = x + 2
|
|
||||||
} else if col-1 >= 0 && line[col-1] == '.' {
|
|
||||||
portalY = y
|
|
||||||
portalX = x - 1
|
|
||||||
} else {
|
|
||||||
panic("!")
|
|
||||||
}
|
|
||||||
} else if len(lines) > row+1 && lines[row+1][col] >= 'A' && lines[row+1][col] <= 'Z' {
|
|
||||||
currPortal.WriteRune(ch)
|
|
||||||
currPortal.WriteRune(rune(lines[row+1][col]))
|
|
||||||
|
|
||||||
if len(lines) > row+2 && lines[row+2][col] == '.' {
|
|
||||||
portalY = y + 2
|
|
||||||
portalX = x
|
|
||||||
} else if row-1 >= 0 && lines[row-1][col] == '.' {
|
|
||||||
portalY = y - 1
|
|
||||||
portalX = x
|
|
||||||
} else {
|
|
||||||
panic("!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if currPortal.Len() == 2 {
|
|
||||||
portalName := currPortal.String()
|
|
||||||
portalVec := u.Vec2i{X: portalX, Y: portalY}
|
|
||||||
|
|
||||||
if portalName == entrancePortal.name {
|
|
||||||
d.entrance = portalVec
|
|
||||||
} else if portalName == exitPortal.name {
|
|
||||||
d.exit = portalVec
|
|
||||||
} else {
|
|
||||||
portal := day20Portal{
|
|
||||||
name: portalName,
|
|
||||||
inner: !d.isOuterPortal(portalVec),
|
|
||||||
}
|
|
||||||
d.portals[portal] = portalVec
|
|
||||||
|
|
||||||
u.AddToArray(&d.portalNames, portalName)
|
|
||||||
}
|
|
||||||
|
|
||||||
currPortal.Reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) Num() int {
|
|
||||||
return 20
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) isPortal(vec u.Vec2i) (bool, int) {
|
|
||||||
if d.grid[vec.Y][vec.X] != day20CellPath {
|
|
||||||
return false, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, name := range d.portalNames {
|
|
||||||
p, exists := d.portals[day20Portal{name: name, inner: !d.isOuterPortal(vec)}]
|
|
||||||
if exists && vec == p {
|
|
||||||
return true, i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) Draw() {
|
|
||||||
for y := range d.grid {
|
|
||||||
for x := range d.grid[y] {
|
|
||||||
switch d.grid[y][x] {
|
|
||||||
case day20CellWall:
|
|
||||||
fmt.Print("█")
|
|
||||||
case day20CellDonutHole:
|
|
||||||
fmt.Print(" ")
|
|
||||||
case day20CellPath:
|
|
||||||
posVec := u.Vec2i{X: x, Y: y}
|
|
||||||
if posVec == d.entrance {
|
|
||||||
fmt.Print("@")
|
|
||||||
} else if posVec == d.exit {
|
|
||||||
fmt.Print("!")
|
|
||||||
} else {
|
|
||||||
isPortal, portalIdx := d.isPortal(posVec)
|
|
||||||
if isPortal {
|
|
||||||
ch := 'a' + portalIdx
|
|
||||||
if ch > 'z' {
|
|
||||||
ch = 'A' + (portalIdx - 26)
|
|
||||||
}
|
|
||||||
fmt.Printf("%c", ch)
|
|
||||||
} else {
|
|
||||||
fmt.Print(" ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) isOuterPortal(pos u.Vec2i) bool {
|
|
||||||
return pos.X == 0 || pos.Y == 0 || pos.X == len(d.grid[0])-1 || pos.Y == len(d.grid)-1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) findAdjacentCells(inPos u.Vec2i) []u.Pair[day20Portal, int] {
|
|
||||||
found := make([]u.Pair[day20Portal, int], 0)
|
|
||||||
|
|
||||||
getAdjacent := func(pos u.Vec2i) []u.Vec2i {
|
|
||||||
retAdjacent := make([]u.Vec2i, 0, len(day20AdjacentOffsets))
|
|
||||||
for _, off := range day20AdjacentOffsets {
|
|
||||||
offVec := u.Vec2i{X: pos.X + off.X, Y: pos.Y + off.Y}
|
|
||||||
if offVec.Y < 0 || offVec.Y >= len(d.grid) || offVec.X < 0 || offVec.X >= len(d.grid[0]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if d.grid[offVec.Y][offVec.X] != day20CellPath {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
retAdjacent = append(retAdjacent, offVec)
|
|
||||||
}
|
|
||||||
|
|
||||||
return retAdjacent
|
|
||||||
}
|
|
||||||
|
|
||||||
queue := make([]u.Pair[int, u.Vec2i], 0)
|
|
||||||
visited := map[u.Vec2i]bool{
|
|
||||||
inPos: true,
|
|
||||||
}
|
|
||||||
for _, adjacent := range getAdjacent(inPos) {
|
|
||||||
queue = append(queue, u.Pair[int, u.Vec2i]{First: 1, Second: adjacent})
|
|
||||||
}
|
|
||||||
|
|
||||||
for len(queue) > 0 {
|
|
||||||
next := queue[0]
|
|
||||||
queue = queue[1:]
|
|
||||||
|
|
||||||
if _, exists := visited[next.Second]; !exists {
|
|
||||||
visited[next.Second] = true
|
|
||||||
|
|
||||||
adjacentIsPortal, portalIdx := d.isPortal(next.Second)
|
|
||||||
if adjacentIsPortal || next.Second == d.entrance || next.Second == d.exit {
|
|
||||||
var portalName string
|
|
||||||
if next.Second == d.entrance {
|
|
||||||
portalName = entrancePortal.name
|
|
||||||
} else if next.Second == d.exit {
|
|
||||||
portalName = exitPortal.name
|
|
||||||
} else {
|
|
||||||
portalName = d.portalNames[portalIdx]
|
|
||||||
}
|
|
||||||
|
|
||||||
alreadyFound := false
|
|
||||||
for _, p := range found {
|
|
||||||
if p.First.name == portalName {
|
|
||||||
alreadyFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !alreadyFound {
|
|
||||||
found = append(found, u.Pair[day20Portal, int]{First: day20Portal{
|
|
||||||
name: portalName,
|
|
||||||
inner: !d.isOuterPortal(next.Second),
|
|
||||||
}, Second: next.First})
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, neighbor := range getAdjacent(next.Second) {
|
|
||||||
if _, exists := visited[neighbor]; !exists {
|
|
||||||
queue = append(queue, u.Pair[int, u.Vec2i]{First: next.First + 1, Second: neighbor})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return found
|
|
||||||
}
|
|
||||||
|
|
||||||
type day20PriorityQueue struct {
|
|
||||||
distance int
|
|
||||||
neighbor day20Portal
|
|
||||||
}
|
|
||||||
type day20PriorityQueueHeap []day20PriorityQueue
|
|
||||||
|
|
||||||
func (h day20PriorityQueueHeap) Len() int { return len(h) }
|
|
||||||
func (h day20PriorityQueueHeap) Less(i, j int) bool { return h[i].distance < h[j].distance }
|
|
||||||
func (h day20PriorityQueueHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
|
||||||
|
|
||||||
func (h *day20PriorityQueueHeap) Push(x any) {
|
|
||||||
*h = append(*h, x.(day20PriorityQueue))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *day20PriorityQueueHeap) Pop() any {
|
|
||||||
old := *h
|
|
||||||
n := len(old)
|
|
||||||
x := old[n-1]
|
|
||||||
*h = old[0 : n-1]
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) dijkstra(graph day20Graph, start, end day20Portal, neighborFunc func(inPortal day20Portal) []u.Pair[day20Portal, int]) int {
|
|
||||||
distance := make(map[day20Portal]int)
|
|
||||||
|
|
||||||
ih := day20PriorityQueueHeap{
|
|
||||||
day20PriorityQueue{
|
|
||||||
distance: 0,
|
|
||||||
neighbor: start,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
heap.Init(&ih)
|
|
||||||
visited := make(map[day20Portal]bool)
|
|
||||||
|
|
||||||
for ih.Len() > 0 {
|
|
||||||
node := heap.Pop(&ih).(day20PriorityQueue)
|
|
||||||
|
|
||||||
if node.neighbor == end {
|
|
||||||
return node.distance
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := visited[node.neighbor]; exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
visited[node.neighbor] = true
|
|
||||||
|
|
||||||
for _, p := range neighborFunc(node.neighbor) {
|
|
||||||
if _, exists := visited[p.First]; exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
newDistance := node.distance + p.Second
|
|
||||||
if dist, exists := distance[p.First]; !exists || newDistance < dist {
|
|
||||||
distance[p.First] = newDistance
|
|
||||||
heap.Push(&ih, day20PriorityQueue{
|
|
||||||
distance: newDistance,
|
|
||||||
neighbor: p.First,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return math.MaxInt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) buildGraph() day20Graph {
|
|
||||||
graph := make(day20Graph, len(d.portals)+1)
|
|
||||||
|
|
||||||
adjacent := d.findAdjacentCells(d.entrance)
|
|
||||||
graph[entrancePortal] = adjacent
|
|
||||||
|
|
||||||
for portal, portalVec := range d.portals {
|
|
||||||
adjacent = d.findAdjacentCells(portalVec)
|
|
||||||
graph[portal] = adjacent
|
|
||||||
}
|
|
||||||
|
|
||||||
return graph
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day20) getDepthNeighbors(graph day20Graph, portal day20Portal) []u.Pair[day20Portal, int] {
|
|
||||||
basePortal := portal
|
|
||||||
basePortal.depth = 0
|
|
||||||
baseNeighbors := graph[basePortal]
|
|
||||||
|
|
||||||
neighbors := make([]u.Pair[day20Portal, int], 0)
|
|
||||||
|
|
||||||
if portal.inner {
|
|
||||||
n := day20Portal{name: portal.name, inner: false, depth: portal.depth + 1}
|
|
||||||
neighbors = append(neighbors, u.Pair[day20Portal, int]{First: n, Second: 1})
|
|
||||||
}
|
|
||||||
|
|
||||||
if portal.depth == 0 {
|
|
||||||
for _, i := range baseNeighbors {
|
|
||||||
if i.First.inner || i.First.name == entrancePortal.name || i.First.name == exitPortal.name {
|
|
||||||
neighbors = append(neighbors, u.Pair[day20Portal, int]{First: i.First, Second: i.Second})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !portal.inner {
|
|
||||||
n := day20Portal{name: portal.name, inner: true, depth: portal.depth - 1}
|
|
||||||
neighbors = append(neighbors, u.Pair[day20Portal, int]{First: n, Second: 1})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, i := range baseNeighbors {
|
|
||||||
if i.First.name != entrancePortal.name && i.First.name != exitPortal.name {
|
|
||||||
n := day20Portal{name: i.First.name, inner: i.First.inner, depth: portal.depth}
|
|
||||||
neighbors = append(neighbors, u.Pair[day20Portal, int]{First: n, Second: i.Second})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return neighbors
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day20) Part1() string {
|
|
||||||
// d.Draw()
|
|
||||||
|
|
||||||
graph := d.buildGraph()
|
|
||||||
|
|
||||||
for portal, adjacent := range graph {
|
|
||||||
if portal.name == entrancePortal.name {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
graph[portal] = append(adjacent, u.Pair[day20Portal, int]{First: day20Portal{name: portal.name, inner: !portal.inner}, Second: 1})
|
|
||||||
}
|
|
||||||
|
|
||||||
distance := d.dijkstra(graph, entrancePortal, exitPortal, func(inPortal day20Portal) []u.Pair[day20Portal, int] { return graph[inPortal] })
|
|
||||||
return fmt.Sprintf("Steps to traverse maze: %s%d%s", u.TextBold, distance, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day20) Part2() string {
|
|
||||||
graph := d.buildGraph()
|
|
||||||
distance := d.dijkstra(graph, entrancePortal, exitPortal, func(inPortal day20Portal) []u.Pair[day20Portal, int] { return d.getDepthNeighbors(graph, inPortal) })
|
|
||||||
return fmt.Sprintf("Steps to traverse recursive maze: %s%d%s", u.TextBold, distance, u.TextReset)
|
|
||||||
}
|
|
86
days/21.go
86
days/21.go
@ -1,86 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Day21 struct {
|
|
||||||
program u.IntcodeProgram
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day21) Parse() {
|
|
||||||
d.program = u.LoadIntcodeProgram("21p")
|
|
||||||
// d.program.SetDebugASCIIPrint(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day21) Num() int {
|
|
||||||
return 21
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day21) Part1() string {
|
|
||||||
// if there's any hole up to 3 ahead of us but there's ground where we'd land if we jumped
|
|
||||||
// (a jump takes 4 spaces), go ahead and jump
|
|
||||||
cmds := []string{
|
|
||||||
// check if a hole at 1 or 2 ahead
|
|
||||||
"NOT A T",
|
|
||||||
"NOT B J",
|
|
||||||
// store that result in J
|
|
||||||
"OR T J",
|
|
||||||
// check if a hole at 3 ahead
|
|
||||||
"NOT C T",
|
|
||||||
// store hole in 1, 2, or 3 in T
|
|
||||||
"OR J T",
|
|
||||||
// set J true if hole in 1, 2, or 3
|
|
||||||
"OR T J",
|
|
||||||
// set J true if also no hole at 4 ahead
|
|
||||||
"AND D J",
|
|
||||||
"WALK",
|
|
||||||
}
|
|
||||||
instructionStr := strings.Join(cmds, "\n") + "\n"
|
|
||||||
d.program.FeedInputString(instructionStr)
|
|
||||||
|
|
||||||
res := d.program.Run()
|
|
||||||
|
|
||||||
return fmt.Sprintf("Hull damage value when walking: %s%d%s", u.TextBold, res, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day21) Part2() string {
|
|
||||||
d.program.Reset()
|
|
||||||
// @
|
|
||||||
// #####.#.##.##.###
|
|
||||||
// ABCDEFGHI
|
|
||||||
// using the first program, this kills us. if we jump, we land at D and H becomes our new D, so it won't jump again.
|
|
||||||
// but if we waited to jump until we got one more ahead, we'd be ok.
|
|
||||||
// so now we want to know essentially the same thing as part 1, but also if our multiple (immediate second jump) would be successful.
|
|
||||||
// in problem terms, that's: if there's a hole at 1 or 2 ahead, and there's a hole at C with ground at H, and there's ground at D.
|
|
||||||
// so now for the above example we'd wait to jump until here:
|
|
||||||
// @
|
|
||||||
// #####.#.##.##.###
|
|
||||||
// ABCDEFGHI
|
|
||||||
// and all will be well.
|
|
||||||
cmds := []string{
|
|
||||||
// check if a hole at 1 or 2 ahead
|
|
||||||
"NOT A J",
|
|
||||||
"NOT B T",
|
|
||||||
// store that result in J
|
|
||||||
"OR T J",
|
|
||||||
// check if a hole at 3 ahead...
|
|
||||||
"NOT C T",
|
|
||||||
// and ground at 8 ahead (so we can immediately jump again if needed)...
|
|
||||||
"AND H T",
|
|
||||||
// combine those into J
|
|
||||||
"OR T J",
|
|
||||||
// and ensure we also still have a place to land if we jumped right away
|
|
||||||
"AND D J",
|
|
||||||
"RUN",
|
|
||||||
}
|
|
||||||
instructionStr := strings.Join(cmds, "\n") + "\n"
|
|
||||||
d.program.FeedInputString(instructionStr)
|
|
||||||
|
|
||||||
res := d.program.Run()
|
|
||||||
|
|
||||||
return fmt.Sprintf("Hull damage value when running: %s%d%s", u.TextBold, res, u.TextReset)
|
|
||||||
}
|
|
155
days/22.go
155
days/22.go
@ -1,155 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"math/big"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type day22Instruction int
|
|
||||||
|
|
||||||
const (
|
|
||||||
day22InstructionNewStack day22Instruction = iota
|
|
||||||
day22InstructionCut
|
|
||||||
day22InstructionDealIncrement
|
|
||||||
)
|
|
||||||
|
|
||||||
type day22Shuffle struct {
|
|
||||||
instruction day22Instruction
|
|
||||||
arg int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Day22 struct {
|
|
||||||
shuffles []day22Shuffle
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day22) Parse() {
|
|
||||||
lines := u.GetStringLines("22p")
|
|
||||||
d.shuffles = make([]day22Shuffle, len(lines))
|
|
||||||
|
|
||||||
for idx, line := range lines {
|
|
||||||
split := strings.Split(line, " ")
|
|
||||||
if split[0] == "deal" {
|
|
||||||
if split[1] == "into" {
|
|
||||||
d.shuffles[idx] = day22Shuffle{instruction: day22InstructionNewStack}
|
|
||||||
} else if split[1] == "with" {
|
|
||||||
arg, err := strconv.Atoi(split[3])
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
d.shuffles[idx] = day22Shuffle{
|
|
||||||
instruction: day22InstructionDealIncrement,
|
|
||||||
arg: arg,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if split[0] == "cut" {
|
|
||||||
arg, err := strconv.Atoi(split[1])
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
d.shuffles[idx] = day22Shuffle{
|
|
||||||
instruction: day22InstructionCut,
|
|
||||||
arg: arg,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day22) Num() int {
|
|
||||||
return 22
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day22) applyShuffle(s day22Shuffle, stack, scratch []int) {
|
|
||||||
switch s.instruction {
|
|
||||||
case day22InstructionNewStack:
|
|
||||||
for i := 0; i < len(stack)/2; i++ {
|
|
||||||
stack[i], stack[len(stack)-1-i] = stack[len(stack)-1-i], stack[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
// there's probably a way to do these two in place...
|
|
||||||
case day22InstructionCut:
|
|
||||||
absArg := int(math.Abs(float64(s.arg)))
|
|
||||||
for i, v := range stack {
|
|
||||||
if s.arg > 0 {
|
|
||||||
if i < absArg {
|
|
||||||
scratch[len(scratch)-absArg+i] = v
|
|
||||||
} else {
|
|
||||||
scratch[i-absArg] = v
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if i < absArg {
|
|
||||||
scratch[i] = stack[len(stack)-absArg+i]
|
|
||||||
} else {
|
|
||||||
scratch[i] = stack[i-absArg]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
copy(stack, scratch)
|
|
||||||
|
|
||||||
case day22InstructionDealIncrement:
|
|
||||||
for i, v := range stack {
|
|
||||||
scratch[(i*s.arg)%len(stack)] = v
|
|
||||||
}
|
|
||||||
copy(stack, scratch)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day22) Part1() string {
|
|
||||||
deckSize := 10007
|
|
||||||
// deckSize := 10
|
|
||||||
|
|
||||||
stack := make([]int, deckSize)
|
|
||||||
for i := range stack {
|
|
||||||
stack[i] = i
|
|
||||||
}
|
|
||||||
|
|
||||||
scratch := make([]int, len(stack))
|
|
||||||
|
|
||||||
for _, s := range d.shuffles {
|
|
||||||
d.applyShuffle(s, stack, scratch)
|
|
||||||
}
|
|
||||||
|
|
||||||
pos := -1
|
|
||||||
for i, v := range stack {
|
|
||||||
if v == 2019 {
|
|
||||||
pos = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("Card 2019 is at position %s%d%s", u.TextBold, pos, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day22) Part2() string {
|
|
||||||
n, iter := big.NewInt(119315717514047), big.NewInt(101741582076661)
|
|
||||||
offset, increment := big.NewInt(0), big.NewInt(1)
|
|
||||||
for _, s := range d.shuffles {
|
|
||||||
switch s.instruction {
|
|
||||||
case day22InstructionNewStack:
|
|
||||||
increment.Mul(increment, big.NewInt(-1))
|
|
||||||
offset.Add(offset, increment)
|
|
||||||
case day22InstructionCut:
|
|
||||||
offset.Add(offset, big.NewInt(0).Mul(big.NewInt(int64(s.arg)), increment))
|
|
||||||
case day22InstructionDealIncrement:
|
|
||||||
increment.Mul(increment, big.NewInt(0).Exp(big.NewInt(int64(s.arg)), big.NewInt(0).Sub(n, big.NewInt(2)), n))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
finalIncr := big.NewInt(0).Exp(increment, iter, n)
|
|
||||||
|
|
||||||
finalOffs := big.NewInt(0).Exp(increment, iter, n)
|
|
||||||
finalOffs.Sub(big.NewInt(1), finalOffs)
|
|
||||||
invmod := big.NewInt(0).Exp(big.NewInt(0).Sub(big.NewInt(1), increment), big.NewInt(0).Sub(n, big.NewInt(2)), n)
|
|
||||||
finalOffs.Mul(finalOffs, invmod)
|
|
||||||
finalOffs.Mul(finalOffs, offset)
|
|
||||||
|
|
||||||
answer := big.NewInt(0).Mul(big.NewInt(2020), finalIncr)
|
|
||||||
answer.Add(answer, finalOffs)
|
|
||||||
answer.Mod(answer, n)
|
|
||||||
|
|
||||||
return fmt.Sprintf("Card at position 2020: %s%d%s", u.TextBold, answer, u.TextReset)
|
|
||||||
}
|
|
170
days/23.go
170
days/23.go
@ -1,170 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type day23Computer struct {
|
|
||||||
program u.IntcodeProgram
|
|
||||||
id int
|
|
||||||
packetQueue chan u.Vec2[int64]
|
|
||||||
outputStep int
|
|
||||||
nextPacketDest int
|
|
||||||
sendingPacket u.Vec2[int64]
|
|
||||||
hasQueuedPacket bool
|
|
||||||
lastReceivedPacket u.Vec2[int64]
|
|
||||||
idle bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day23) makeComputer(id int) *day23Computer {
|
|
||||||
c := &day23Computer{
|
|
||||||
program: d.program.Copy(),
|
|
||||||
id: id,
|
|
||||||
packetQueue: make(chan u.Vec2[int64]),
|
|
||||||
idle: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
type Day23 struct {
|
|
||||||
program u.IntcodeProgram
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day23) Parse() {
|
|
||||||
d.program = u.LoadIntcodeProgram("23p")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day23) Num() int {
|
|
||||||
return 23
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day23) initComputers() []*day23Computer {
|
|
||||||
computers := make([]*day23Computer, 50)
|
|
||||||
for i := range computers {
|
|
||||||
computers[i] = d.makeComputer(i)
|
|
||||||
}
|
|
||||||
return computers
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day23) execComputers(computers []*day23Computer, nat chan u.Vec2[int64]) *sync.WaitGroup {
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
wg.Add(len(computers))
|
|
||||||
for _, c := range computers {
|
|
||||||
go func(c *day23Computer) {
|
|
||||||
bootedUp := false
|
|
||||||
c.program.RunIn(func(inputStep int) int64 {
|
|
||||||
if !bootedUp {
|
|
||||||
bootedUp = true
|
|
||||||
return int64(c.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.hasQueuedPacket {
|
|
||||||
// fmt.Printf(" %d finished processing packet %v\n", c.id, c.lastReceivedPacket)
|
|
||||||
c.hasQueuedPacket = false
|
|
||||||
return c.lastReceivedPacket.Y
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case c.lastReceivedPacket = <-c.packetQueue:
|
|
||||||
// fmt.Printf("computer %d received packet %v\n", c.id, packet)
|
|
||||||
c.hasQueuedPacket = true
|
|
||||||
return c.lastReceivedPacket.X
|
|
||||||
default:
|
|
||||||
c.idle = true
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
}, func(val int64, state u.IntcodeProgramState) {
|
|
||||||
c.idle = false
|
|
||||||
switch c.outputStep {
|
|
||||||
case 0:
|
|
||||||
c.nextPacketDest = int(val)
|
|
||||||
case 1:
|
|
||||||
c.sendingPacket.X = val
|
|
||||||
case 2:
|
|
||||||
c.sendingPacket.Y = val
|
|
||||||
|
|
||||||
if c.nextPacketDest == 255 {
|
|
||||||
// fmt.Printf("computer %d sending %v to 255\n", c.id, c.sendingPacket)
|
|
||||||
nat <- c.sendingPacket
|
|
||||||
} else {
|
|
||||||
// fmt.Printf("computer %d sending %v to computer %d\n", c.id, c.sendingPacket, c.nextPacketDest)
|
|
||||||
computers[c.nextPacketDest].packetQueue <- c.sendingPacket
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.outputStep = (c.outputStep + 1) % 3
|
|
||||||
})
|
|
||||||
|
|
||||||
wg.Done()
|
|
||||||
}(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
return wg
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day23) Part1() string {
|
|
||||||
computers := d.initComputers()
|
|
||||||
natChan := make(chan u.Vec2[int64])
|
|
||||||
wg := d.execComputers(computers, natChan)
|
|
||||||
|
|
||||||
answer := <-natChan
|
|
||||||
for _, c := range computers {
|
|
||||||
c.program.Stop()
|
|
||||||
}
|
|
||||||
// not really necessary, but let's make sure they all shut down in case
|
|
||||||
// we're running all days at once
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
return fmt.Sprintf("First packet sent to 255 Y value: %s%d%s", u.TextBold, answer.Y, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day23) Part2() string {
|
|
||||||
computers := d.initComputers()
|
|
||||||
natChan := make(chan u.Vec2[int64])
|
|
||||||
wg := d.execComputers(computers, natChan)
|
|
||||||
|
|
||||||
answerChan := make(chan int64)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
var currVal u.Vec2[int64]
|
|
||||||
var lastVal u.Vec2[int64]
|
|
||||||
hasReceived := false
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case currVal = <-natChan:
|
|
||||||
hasReceived = true
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
allIdle := true
|
|
||||||
for _, c := range computers {
|
|
||||||
if !c.idle {
|
|
||||||
allIdle = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if allIdle && hasReceived {
|
|
||||||
// fmt.Printf("all idle, sending %v to computer 0\n", currVal)
|
|
||||||
if lastVal.Y == currVal.Y {
|
|
||||||
// fmt.Printf("found answer? %d\n", currVal.Y)
|
|
||||||
answerChan <- currVal.Y
|
|
||||||
}
|
|
||||||
computers[0].packetQueue <- currVal
|
|
||||||
lastVal = currVal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
answer := <-answerChan
|
|
||||||
for _, c := range computers {
|
|
||||||
c.program.Stop()
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
return fmt.Sprintf("First Y value sent to the NAT twice in a row: %s%d%s", u.TextBold, answer, u.TextReset)
|
|
||||||
}
|
|
289
days/24.go
289
days/24.go
@ -1,289 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
day24AdjacentOffsets = []u.Vec2i{
|
|
||||||
{X: -1, Y: 0},
|
|
||||||
{X: 1, Y: 0},
|
|
||||||
{X: 0, Y: -1},
|
|
||||||
{X: 0, Y: 1},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type Day24 struct {
|
|
||||||
grid [][]bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day24) Parse() {
|
|
||||||
lines := u.GetStringLines("24p")
|
|
||||||
d.grid = make([][]bool, len(lines))
|
|
||||||
for i, line := range lines {
|
|
||||||
d.grid[i] = make([]bool, len(line))
|
|
||||||
for j, ch := range line {
|
|
||||||
d.grid[i][j] = ch == '#'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day24) Num() int {
|
|
||||||
return 24
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day24) calcActivatedNeighbors(grid [][]bool, i, j int) int {
|
|
||||||
activatedNeighbors := 0
|
|
||||||
for _, o := range day24AdjacentOffsets {
|
|
||||||
newI := i + o.X
|
|
||||||
newJ := j + o.Y
|
|
||||||
if newI < 0 || newI >= len(grid) || newJ < 0 || newJ >= len(grid[i]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if grid[newI][newJ] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return activatedNeighbors
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day24) recursiveCalcActivatedNeighbors(gridMap map[int][][]bool, mapIdx, i, j int) int {
|
|
||||||
activatedNeighbors := 0
|
|
||||||
numNeighbors := 0
|
|
||||||
thisGrid := gridMap[mapIdx]
|
|
||||||
for _, o := range day24AdjacentOffsets {
|
|
||||||
newI := i + o.X
|
|
||||||
newJ := j + o.Y
|
|
||||||
if newI < 0 || newI >= len(thisGrid) || newJ < 0 || newJ >= len(thisGrid[i]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if newI == 2 && newJ == 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
numNeighbors++
|
|
||||||
if thisGrid[newI][newJ] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkLower := (i == 1 && j == 2) ||
|
|
||||||
(i == 2 && (j == 1 || j == 3)) ||
|
|
||||||
(i == 3 && j == 2)
|
|
||||||
if checkLower {
|
|
||||||
if lowerGrid, exists := gridMap[mapIdx+1]; exists {
|
|
||||||
if i == 1 {
|
|
||||||
for _, b := range lowerGrid[0] {
|
|
||||||
numNeighbors++
|
|
||||||
if b {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if i == 2 {
|
|
||||||
if j == 1 {
|
|
||||||
for _, r := range lowerGrid {
|
|
||||||
numNeighbors++
|
|
||||||
if r[0] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if j == 3 {
|
|
||||||
for _, r := range lowerGrid {
|
|
||||||
numNeighbors++
|
|
||||||
if r[len(lowerGrid[0])-1] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if i == 3 {
|
|
||||||
for _, b := range lowerGrid[len(lowerGrid)-1] {
|
|
||||||
numNeighbors++
|
|
||||||
if b {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkUpper := (i == 0) || (i == len(thisGrid)-1) ||
|
|
||||||
((i != 0 && i != len(thisGrid)) && (j == 0 || j == len(thisGrid[0])-1))
|
|
||||||
if checkUpper {
|
|
||||||
if upperGrid, exists := gridMap[mapIdx-1]; exists {
|
|
||||||
if i == 0 {
|
|
||||||
numNeighbors++
|
|
||||||
if upperGrid[1][2] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
} else if i == len(thisGrid)-1 {
|
|
||||||
numNeighbors++
|
|
||||||
if upperGrid[3][2] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if j == 0 {
|
|
||||||
numNeighbors++
|
|
||||||
if upperGrid[2][1] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
} else if j == len(thisGrid[0])-1 {
|
|
||||||
numNeighbors++
|
|
||||||
if upperGrid[2][3] {
|
|
||||||
activatedNeighbors++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return activatedNeighbors
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day24) calcRating(grid [][]bool) int {
|
|
||||||
rating := 0
|
|
||||||
for i, r := range grid {
|
|
||||||
for j := range r {
|
|
||||||
pow := (i * len(r)) + j
|
|
||||||
if grid[i][j] {
|
|
||||||
result := int(math.Pow(2, float64(pow)))
|
|
||||||
rating += result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rating
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day24) getNumBugs(gridMap map[int][][]bool) int {
|
|
||||||
ret := 0
|
|
||||||
for _, v := range gridMap {
|
|
||||||
for _, r := range v {
|
|
||||||
for _, b := range r {
|
|
||||||
if b {
|
|
||||||
ret++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func copy2d[T comparable](dest [][]T, src [][]T) {
|
|
||||||
for i, r := range src {
|
|
||||||
copy(dest[i], r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day24) Draw(grid [][]bool) {
|
|
||||||
for _, r := range grid {
|
|
||||||
for _, c := range r {
|
|
||||||
if c {
|
|
||||||
fmt.Print("#")
|
|
||||||
} else {
|
|
||||||
fmt.Print(".")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day24) Part1() string {
|
|
||||||
grid := make([][]bool, len(d.grid))
|
|
||||||
scratch := make([][]bool, len(grid))
|
|
||||||
for i, g := range d.grid {
|
|
||||||
grid[i] = make([]bool, len(g))
|
|
||||||
scratch[i] = make([]bool, len(g))
|
|
||||||
copy(grid[i], d.grid[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
found := false
|
|
||||||
answer := 0
|
|
||||||
seenRatings := make([]int, 0)
|
|
||||||
for i := 1; !found; i++ {
|
|
||||||
// d.Draw(grid)
|
|
||||||
for i, r := range grid {
|
|
||||||
for j := range r {
|
|
||||||
numActivated := d.calcActivatedNeighbors(grid, i, j)
|
|
||||||
if grid[i][j] {
|
|
||||||
scratch[i][j] = numActivated == 1
|
|
||||||
} else {
|
|
||||||
scratch[i][j] = numActivated == 1 || numActivated == 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rating := d.calcRating(scratch)
|
|
||||||
if u.ArrayContains(seenRatings, rating) {
|
|
||||||
found = true
|
|
||||||
// d.Draw(scratch)
|
|
||||||
answer = rating
|
|
||||||
}
|
|
||||||
seenRatings = append(seenRatings, rating)
|
|
||||||
copy2d(grid, scratch)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("First repeated biodiversity rating is %s%d%s", u.TextBold, answer, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day24) Part2() string {
|
|
||||||
makeGrid := func(initialGrid [][]bool) ([][]bool, [][]bool) {
|
|
||||||
grid := make([][]bool, len(d.grid))
|
|
||||||
scratch := make([][]bool, len(grid))
|
|
||||||
for i, g := range d.grid {
|
|
||||||
grid[i] = make([]bool, len(g))
|
|
||||||
scratch[i] = make([]bool, len(g))
|
|
||||||
if initialGrid != nil {
|
|
||||||
copy(grid[i], initialGrid[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return grid, scratch
|
|
||||||
}
|
|
||||||
|
|
||||||
gridMap := make(map[int][][]bool)
|
|
||||||
scratchMap := make(map[int][][]bool)
|
|
||||||
gridMap[0], scratchMap[0] = makeGrid(d.grid)
|
|
||||||
|
|
||||||
min := 0
|
|
||||||
max := 0
|
|
||||||
|
|
||||||
for i := 0; i < 200; i++ {
|
|
||||||
gridMap[min-1], scratchMap[min-1] = makeGrid(nil)
|
|
||||||
gridMap[max+1], scratchMap[max+1] = makeGrid(nil)
|
|
||||||
min, max = min-1, max+1
|
|
||||||
|
|
||||||
// if i == 10 {
|
|
||||||
// keys := u.MapKeys(gridMap)
|
|
||||||
// sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
|
|
||||||
// for _, k := range keys {
|
|
||||||
// fmt.Println("Depth", k)
|
|
||||||
// d.Draw(gridMap[k])
|
|
||||||
// }
|
|
||||||
// fmt.Println("# bugs:", d.numBugs(gridMap))
|
|
||||||
// }
|
|
||||||
|
|
||||||
for depth, grid := range gridMap {
|
|
||||||
for i, r := range grid {
|
|
||||||
for j := range r {
|
|
||||||
if i == 2 && j == 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
numActivated := d.recursiveCalcActivatedNeighbors(gridMap, depth, i, j)
|
|
||||||
if grid[i][j] {
|
|
||||||
scratchMap[depth][i][j] = numActivated == 1
|
|
||||||
} else {
|
|
||||||
scratchMap[depth][i][j] = numActivated == 1 || numActivated == 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for d := range gridMap {
|
|
||||||
copy2d(gridMap[d], scratchMap[d])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("Bugs present after 200 minutes: %s%d%s", u.TextBold, d.getNumBugs(gridMap), u.TextReset)
|
|
||||||
}
|
|
61
days/25.go
61
days/25.go
@ -1,61 +0,0 @@
|
|||||||
package days
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
u "parnic.com/aoc2019/utilities"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Day25 struct {
|
|
||||||
program u.IntcodeProgram
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day25) Parse() {
|
|
||||||
d.program = u.LoadIntcodeProgram("25p")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Day25) Num() int {
|
|
||||||
return 25
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day25) Part1() string {
|
|
||||||
lastCmdStrings := make([]string, 0)
|
|
||||||
sb := strings.Builder{}
|
|
||||||
|
|
||||||
inReader := bufio.NewReader(os.Stdin)
|
|
||||||
d.program.SetDebugASCIIPrint(true)
|
|
||||||
d.program.RunIn(func(inputStep int) int64 {
|
|
||||||
lastCmdStrings = lastCmdStrings[:0]
|
|
||||||
|
|
||||||
text, _ := inReader.ReadString('\n')
|
|
||||||
d.program.FeedInputString(text[1:])
|
|
||||||
return int64(text[0])
|
|
||||||
}, func(val int64, state u.IntcodeProgramState) {
|
|
||||||
if val == '\n' {
|
|
||||||
str := sb.String()
|
|
||||||
if len(str) > 0 {
|
|
||||||
lastCmdStrings = append(lastCmdStrings, sb.String())
|
|
||||||
sb.Reset()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sb.WriteRune(rune(val))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
lastString := lastCmdStrings[len(lastCmdStrings)-1]
|
|
||||||
var answer string
|
|
||||||
if idx := strings.Index(lastString, " by typing "); idx >= 0 {
|
|
||||||
startIdx := idx + len(" by typing ")
|
|
||||||
endIdx := startIdx + strings.Index(lastString[startIdx:], " ")
|
|
||||||
answer = lastString[startIdx:endIdx]
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("Door passcode: %s%s%s", u.TextBold, answer, u.TextReset)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Day25) Part2() string {
|
|
||||||
return "There is no part 2"
|
|
||||||
}
|
|
@ -1 +1 @@
|
|||||||
1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1101,0,3,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1102,252,1,1023,1102,36,1,1008,1102,24,1,1017,1101,25,0,1013,1102,479,1,1026,1101,0,259,1022,1102,1,38,1001,1102,1,713,1024,1101,0,708,1025,1102,1,22,1006,1101,0,32,1010,1101,476,0,1027,1102,1,516,1029,1102,1,34,1009,1101,0,23,1016,1102,1,37,1011,1102,525,1,1028,1101,0,35,1004,1102,31,1,1002,1102,39,1,1019,1102,28,1,1015,1102,1,1,1021,1101,0,30,1007,1101,0,27,1014,1101,21,0,1018,1101,0,29,1005,1102,26,1,1000,1102,1,0,1020,1101,0,20,1012,1101,33,0,1003,109,13,21108,40,40,6,1005,1019,199,4,187,1106,0,203,1001,64,1,64,1002,64,2,64,109,15,1205,-7,221,4,209,1001,64,1,64,1105,1,221,1002,64,2,64,109,-25,1208,-3,26,63,1005,63,243,4,227,1001,64,1,64,1106,0,243,1002,64,2,64,109,25,2105,1,-5,1001,64,1,64,1106,0,261,4,249,1002,64,2,64,109,-4,21108,41,42,-8,1005,1016,281,1001,64,1,64,1106,0,283,4,267,1002,64,2,64,109,-6,1206,2,301,4,289,1001,64,1,64,1105,1,301,1002,64,2,64,109,-4,21102,42,1,2,1008,1016,42,63,1005,63,323,4,307,1106,0,327,1001,64,1,64,1002,64,2,64,109,-7,2108,35,1,63,1005,63,343,1105,1,349,4,333,1001,64,1,64,1002,64,2,64,109,-13,1208,7,35,63,1005,63,369,1001,64,1,64,1106,0,371,4,355,1002,64,2,64,109,24,21102,43,1,-1,1008,1017,42,63,1005,63,391,1105,1,397,4,377,1001,64,1,64,1002,64,2,64,109,-13,2101,0,-4,63,1008,63,38,63,1005,63,419,4,403,1105,1,423,1001,64,1,64,1002,64,2,64,109,21,1206,-5,435,1106,0,441,4,429,1001,64,1,64,1002,64,2,64,109,-22,21101,44,0,10,1008,1014,44,63,1005,63,463,4,447,1105,1,467,1001,64,1,64,1002,64,2,64,109,25,2106,0,-2,1106,0,485,4,473,1001,64,1,64,1002,64,2,64,109,-19,2107,37,-2,63,1005,63,501,1106,0,507,4,491,1001,64,1,64,1002,64,2,64,109,8,2106,0,10,4,513,1001,64,1,64,1105,1,525,1002,64,2,64,109,-6,21107,45,46,0,1005,1012,547,4,531,1001,64,1,64,1105,1,547,1002,64,2,64,109,-5,1202,-1,1,63,1008,63,21,63,1005,63,567,1105,1,573,4,553,1001,64,1,64,1002,64,2,64,109,2,1207,-3,21,63,1005,63,589,1105,1,595,4,579,1001,64,1,64,1002,64,2,64,109,1,1201,-8,0,63,1008,63,34,63,1005,63,619,1001,64,1,64,1106,0,621,4,601,1002,64,2,64,109,-6,2102,1,-1,63,1008,63,33,63,1005,63,643,4,627,1105,1,647,1001,64,1,64,1002,64,2,64,109,10,21101,46,0,3,1008,1017,43,63,1005,63,667,1106,0,673,4,653,1001,64,1,64,1002,64,2,64,109,-13,2102,1,8,63,1008,63,35,63,1005,63,697,1001,64,1,64,1106,0,699,4,679,1002,64,2,64,109,23,2105,1,0,4,705,1105,1,717,1001,64,1,64,1002,64,2,64,109,-1,1205,-3,729,1106,0,735,4,723,1001,64,1,64,1002,64,2,64,109,-15,2101,0,0,63,1008,63,38,63,1005,63,755,1106,0,761,4,741,1001,64,1,64,1002,64,2,64,109,-2,2107,28,-1,63,1005,63,779,4,767,1106,0,783,1001,64,1,64,1002,64,2,64,109,-2,2108,35,0,63,1005,63,801,4,789,1105,1,805,1001,64,1,64,1002,64,2,64,109,1,1201,-5,0,63,1008,63,26,63,1005,63,831,4,811,1001,64,1,64,1105,1,831,1002,64,2,64,109,-5,1207,5,30,63,1005,63,849,4,837,1106,0,853,1001,64,1,64,1002,64,2,64,109,2,1202,-2,1,63,1008,63,26,63,1005,63,879,4,859,1001,64,1,64,1105,1,879,1002,64,2,64,109,15,21107,47,46,0,1005,1017,899,1001,64,1,64,1105,1,901,4,885,4,64,99,21102,1,27,1,21101,915,0,0,1106,0,922,21201,1,66416,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21102,942,1,0,1105,1,922,21202,1,1,-1,21201,-2,-3,1,21102,1,957,0,1105,1,922,22201,1,-1,-2,1105,1,968,22102,1,-2,-2,109,-3,2105,1,0
|
1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1101,3,0,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1102,1,31,1018,1102,352,1,1023,1101,0,1,1021,1101,0,33,1003,1102,1,36,1007,1102,21,1,1005,1101,359,0,1022,1101,0,787,1024,1102,1,24,1011,1101,30,0,1014,1101,22,0,1016,1101,0,0,1020,1102,1,29,1000,1101,778,0,1025,1102,23,1,1017,1102,1,28,1002,1101,38,0,1019,1102,1,27,1013,1102,1,32,1012,1101,0,37,1006,1101,444,0,1027,1102,1,20,1009,1101,0,447,1026,1101,0,39,1008,1101,35,0,1010,1102,559,1,1028,1102,26,1,1004,1102,1,25,1015,1102,1,34,1001,1101,0,554,1029,109,-3,2101,0,9,63,1008,63,34,63,1005,63,205,1001,64,1,64,1105,1,207,4,187,1002,64,2,64,109,23,21107,40,39,-7,1005,1013,227,1001,64,1,64,1106,0,229,4,213,1002,64,2,64,109,-17,1202,-2,1,63,1008,63,36,63,1005,63,249,1106,0,255,4,235,1001,64,1,64,1002,64,2,64,109,-6,1202,10,1,63,1008,63,36,63,1005,63,277,4,261,1106,0,281,1001,64,1,64,1002,64,2,64,109,-2,1208,9,26,63,1005,63,303,4,287,1001,64,1,64,1106,0,303,1002,64,2,64,109,32,1206,-7,321,4,309,1001,64,1,64,1106,0,321,1002,64,2,64,109,-29,1207,7,20,63,1005,63,337,1105,1,343,4,327,1001,64,1,64,1002,64,2,64,109,27,2105,1,-2,1001,64,1,64,1106,0,361,4,349,1002,64,2,64,109,-25,2108,39,7,63,1005,63,377,1106,0,383,4,367,1001,64,1,64,1002,64,2,64,109,1,1201,6,0,63,1008,63,36,63,1005,63,409,4,389,1001,64,1,64,1105,1,409,1002,64,2,64,109,1,2102,1,1,63,1008,63,33,63,1005,63,435,4,415,1001,64,1,64,1105,1,435,1002,64,2,64,109,28,2106,0,-3,1106,0,453,4,441,1001,64,1,64,1002,64,2,64,109,-13,21101,41,0,1,1008,1018,44,63,1005,63,477,1001,64,1,64,1106,0,479,4,459,1002,64,2,64,109,4,21108,42,42,-2,1005,1019,501,4,485,1001,64,1,64,1106,0,501,1002,64,2,64,109,-21,2101,0,2,63,1008,63,28,63,1005,63,523,4,507,1105,1,527,1001,64,1,64,1002,64,2,64,109,26,1205,-5,545,4,533,1001,64,1,64,1105,1,545,1002,64,2,64,109,3,2106,0,-1,4,551,1106,0,563,1001,64,1,64,1002,64,2,64,109,-33,1201,4,0,63,1008,63,28,63,1005,63,583,1105,1,589,4,569,1001,64,1,64,1002,64,2,64,109,11,2107,27,-3,63,1005,63,609,1001,64,1,64,1106,0,611,4,595,1002,64,2,64,109,8,21102,43,1,3,1008,1018,43,63,1005,63,637,4,617,1001,64,1,64,1105,1,637,1002,64,2,64,109,-5,21108,44,41,0,1005,1010,653,1105,1,659,4,643,1001,64,1,64,1002,64,2,64,109,-13,2108,21,8,63,1005,63,681,4,665,1001,64,1,64,1106,0,681,1002,64,2,64,109,6,1207,0,34,63,1005,63,703,4,687,1001,64,1,64,1105,1,703,1002,64,2,64,109,7,1208,-7,35,63,1005,63,723,1001,64,1,64,1106,0,725,4,709,1002,64,2,64,109,-13,2102,1,7,63,1008,63,23,63,1005,63,745,1105,1,751,4,731,1001,64,1,64,1002,64,2,64,109,13,1205,10,767,1001,64,1,64,1105,1,769,4,757,1002,64,2,64,109,14,2105,1,0,4,775,1001,64,1,64,1106,0,787,1002,64,2,64,109,-20,21107,45,46,7,1005,1011,809,4,793,1001,64,1,64,1105,1,809,1002,64,2,64,109,-3,2107,25,3,63,1005,63,827,4,815,1106,0,831,1001,64,1,64,1002,64,2,64,109,13,1206,7,847,1001,64,1,64,1106,0,849,4,837,1002,64,2,64,109,-11,21101,46,0,7,1008,1010,46,63,1005,63,871,4,855,1106,0,875,1001,64,1,64,1002,64,2,64,109,15,21102,47,1,-4,1008,1014,48,63,1005,63,895,1106,0,901,4,881,1001,64,1,64,4,64,99,21102,27,1,1,21101,0,915,0,1106,0,922,21201,1,63208,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21102,1,942,0,1106,0,922,21202,1,1,-1,21201,-2,-3,1,21101,957,0,0,1105,1,922,22201,1,-1,-2,1106,0,968,21201,-2,0,-2,109,-3,2106,0,0
|
@ -1,4 +1,4 @@
|
|||||||
<x=14, y=4, z=5>
|
<x=-6, y=-5, z=-8>
|
||||||
<x=12, y=10, z=8>
|
<x=0, y=-3, z=-13>
|
||||||
<x=1, y=7, z=-10>
|
<x=-15, y=10, z=-11>
|
||||||
<x=16, y=-5, z=3>
|
<x=-3, y=-8, z=3>
|
File diff suppressed because one or more lines are too long
@ -1,81 +0,0 @@
|
|||||||
#################################################################################
|
|
||||||
#...............#.......#...............#.........#.......#.......#.....#.......#
|
|
||||||
#.#########.#.###.#####.#.#.#######.#####.#######.#.#######.#.###.###.#.#.#####.#
|
|
||||||
#.#.#.....#.#.#...#...#..f#...#.....#...#...#.....#.........#...#.....#...#m....#
|
|
||||||
#.#.#.###.###.#.#####.#######.#######.#.#.#.#.#######.#########.###########.#####
|
|
||||||
#...#...#.#...#.......#.....#.#.......#.#.#.#...#...#...#.......#..h......#.....#
|
|
||||||
###.###.#.#.#########.#.###.#T#.#######.###.###.#B#.#.###.#######.#######.#####.#
|
|
||||||
#...#...#...#.....#...#...#.#...#.....#.#...#.#...#.#.#...#.........#...#.......#
|
|
||||||
#####.#######.###.#.###.#.#######.###.#.#.###.#####.###.#.###########.#.#######.#
|
|
||||||
#...#...#.....#.#...#.#.#.....#...#.....#.#.....#...#...#.#...........#.#.....#.#
|
|
||||||
#.#.###.#.#####.#####.#.#####.#.###.#####.#.###.#.###.#####.###########.#.###.#.#
|
|
||||||
#.#.....#.#.....#.........#...#...#.#...#.#...#..x#...W.....#.....#.....#.#...#.#
|
|
||||||
#.#######.###.#.#########.#.#####.###.#.#.###.#######.#######.###.#.#####.#.#####
|
|
||||||
#.........#...#.......#.#.#.#...#.....#.#.#.#.#.....#...#.....#...#.#.....#.....#
|
|
||||||
#.#########O#########.#.#.#.#.#.#.#####.#.#.#.###.#.#.###.#####.###.#.#########.#
|
|
||||||
#.#.........#.........#...#.#.#.#...#.#.#.#.......#.#.#...#...#.#.......#.....#.#
|
|
||||||
#.#####.#########.#########.#.#.###.#.#.#.#########.###.###.###.#####.###.###.#.#
|
|
||||||
#.....#...#.....#.#.........#.#.#.....#.#.....#.....#...#...........#.#...#e..#.#
|
|
||||||
#####.###.#K###.#.#####.#####.#.#######.#####.#####.#.#.###########.###.###.###.#
|
|
||||||
#...#.....#.#...#.......#.....#.#.......#.....#...#...#.#.........#.....#.#.#...#
|
|
||||||
#.#####.###.#.#########.#.#####.#.#####.#.#####.#.#######.#####.#.#######.#.#.#.#
|
|
||||||
#.#j..#.#...#a..#.....#.#.#.......#.....#.......#...........#.#.#.......#.#...#.#
|
|
||||||
#.#.#.#.#.#####.#.#####.#.#############.#.###################.#########.#.#####.#
|
|
||||||
#...#.#.#.#...#...#.....#.#..z..#.....#.#.....#.......#.....#...#...#...#...#...#
|
|
||||||
#.###.#.#.###.#####.#####.#.###.#.###.#######.#.#.#####.###.###.#.#.#.###.###.###
|
|
||||||
#.#...#.#.....#.#...#...#.#...#.#.#.#...#.....#.#.....#...#.....#.#...#.#...#...#
|
|
||||||
###.###.#####.#.#.###.#.#.###.#.#.#.###.#.###########.###.#######.#####.#.#.###.#
|
|
||||||
#...#...#...#.#.......#.#.....#.#.....#.#.#.............#...#...#...#.....#.#...#
|
|
||||||
#.#.#.#####.#.#############.###.###.###.#.#.#########.#####.###.#.#.#####.#.#.###
|
|
||||||
#.#.#.#.....#.............#...#.....#...#.#.....#...#.#.....#...#.#.#...#.#.#.#.#
|
|
||||||
#.###.#.#.###############.###.#####.#.#.#.#####.#.#.#.#.#####.###.#.#.#.#.#.#.#.#
|
|
||||||
#.#...#.#.......#.........#...#...#.#.#.#.#.....#.#...#.#.........#.#.#.#.#...#.#
|
|
||||||
#.#.#######.###.#.#########.###.#.###.#.#.#.###########.#.#########.#.#.#####.#.#
|
|
||||||
#.#.......#...#.#.#.......#...#.#.#...#.#.#...#.......#.#.#.......#...#.#...#c..#
|
|
||||||
#.#######.#.#.###.###.###.#####.#.#.###.#.###.#.#####.#.###.#####.#.###.#.#.###.#
|
|
||||||
#.L..q..#.#.#...#...#.#.#.....#.#...#...#...#.....#...#.....#.....#...#...#.#...#
|
|
||||||
#.#######.#####.###.#.#.#####.#.#####.#####.#######S#########.#############.#.###
|
|
||||||
#...#...#.#.......#...#.#.....#.#...#...#...#.....#.....#...#.#.....#.....#k#...#
|
|
||||||
#.#.#.#.#.#.#####.#####.#.#####.#.#.###.#.###.###.###.#.###.#.#.###.#.###.#.###.#
|
|
||||||
#.#...#.....#...........#.......#.#...........#.......#.....#...#.....#.....#...#
|
|
||||||
#######################################.@.#######################################
|
|
||||||
#.#...#...........#u....#...#.......#...............#.....#...................#.#
|
|
||||||
#.#.#.#.#####.###.#.#.#.#.#.#.#.#####.#.#####.#####.#.###.#.###.#############.#.#
|
|
||||||
#.#.#...#...#...#.#.#.#.#.#...#.#s....#.#.....#...#.#.#.#..p#.#.#.....#.....#...#
|
|
||||||
#.#.#######.###.###.#.###.#####.#.#####.#.#######.#.#.#.#####.#.#.###.#.###.###.#
|
|
||||||
#...#.........#.#...#.#...#...#...#...#.#...#.....#...#.......#.#.#.#.....#.#.#.#
|
|
||||||
#.###.#.#####.#.#.###.#.###.#######.#.#.#.#.#.###.#####.#######.#.#.#######.#.#.#
|
|
||||||
#...#.#.#.....#...#...#.#...#.....#.#...#.#.#.#...#.....#.......#.#...#.V...#...#
|
|
||||||
###.###.#.#########.###.#.#.#.###.#.###.###.#.#####.#.###.#######.###.#.#####.###
|
|
||||||
#.#.....#.#.....#...#.....#.#...#...#...#...#.#.....#.......#...#.#...#.#.....#.#
|
|
||||||
#.#######.#N#.#.#.#.#.#########.#.#######.###.#.#############.#.#.#.#.#.#.#####.#
|
|
||||||
#.......#.#.#.#.#.#.#.#...#.....#.#.....#.#.........#.........#.#...#.#.#.....U.#
|
|
||||||
#.#######.###.#.#.###.#.#P#.#######.###.#.###.#######.#########.#####.#.#######.#
|
|
||||||
#.#.....#...#.#.#.....#.#...#.......#...#...#...#.....#.......#.......#.#...#...#
|
|
||||||
#.#.###.###.#.#########.###.#.#######.#####.###.#.#####.###.###########.#.#.#.###
|
|
||||||
#...#...#.#.#.#.....#...#...#.#.....#...#...#...#.......#...#.........#.#.#.#.#.#
|
|
||||||
#.###.#.#.#.#.#.#.###.#######.#.###.###.#.#####.#####.#####.#.#######.#.#.#Q#.#.#
|
|
||||||
#.#...#...#.#...#...#.....#...#.#...#...#.....#.....#.#.Yi#.#.#...#...#.#.#.#...#
|
|
||||||
#.#.#######.###.###.#####.#.###.#.#.#.###.###.#######.#.#.#.#.###.#.###.#.#.###.#
|
|
||||||
#.#.......#...#.#.....#...#.#...#.#.#...#.#...#.......#.#.#.#...#.....#.#.#.#...#
|
|
||||||
#.#######.###.###.#.###.###.#####.#####.#.#.#.#.#######.#.#.###.#####.#.#.#.#####
|
|
||||||
#.#.....#.....#...#.#.#.........#.....#.#.#.#.#.#...#...#.#.#.#.#...#...#.#.....#
|
|
||||||
#.#.###.#######.#####.#########.#.#.###.#.#.#.#.#.###.###.#.#.#.#.#.#####.#####.#
|
|
||||||
#.#.#.....#.........#.#.....#.#.#.#b#...#.#.#.#.#.#..y#.#.#.#.#.#.#...#...#.....#
|
|
||||||
#.###.#####.#######.#.#.###.#.#.#.#.#.#####.###.#.#.###.#.###.#.#.###.#.###.###.#
|
|
||||||
#.E.#....d..#.......#...#.#.#.#.#.#.#...#...#...#.#...#.#...I.#...#..l#.#...#...#
|
|
||||||
###.#.#######.###########F#.#.#.###.###.#.#.#.###.###.#.#########.#.###.#.###J###
|
|
||||||
#...#...#...#...........#...#.......#...#.#.#.#.....#.G.#.......#.#.....#.#.#.#.#
|
|
||||||
#.#####.#.#########.#.#.#.#########.#.#.#.###.#####.###.#.###.#.#####.###.#.#.#.#
|
|
||||||
#..v..#...#.......#.#.#.#.#...#.....#.#.#...#.......#.#.#...#.#.....#.#...#.#...#
|
|
||||||
#####.#####.#####.###.###.#.#.#.#####.#.#Z#.#######X#.#.#####.#####.#.#.###.###.#
|
|
||||||
#...#.....#...#.....#...#...#.#.#...#.#.#.#.......#...#.....#.....#.#.#.#...#...#
|
|
||||||
#.#######.#.#.#####.###.#####.#.#.###.#.###.#.#####.#######.#.###.#.###.#.###.###
|
|
||||||
#.........#.#.#...#...#...#...#...#...#.#...#.#...#.#.R....g#.#...#.....#.#...#.#
|
|
||||||
#.###########.#.#.###.###.#.###.###.###.#.#####.#.#.#.#########.#########.#.###.#
|
|
||||||
#...#.#.....#...#.#.#.#...#..t#.#...#...#.#.....#...#...#.....#.#..n....#.M.#...#
|
|
||||||
###.#.#.#.#.#####.#.#.#.#####.###.#####.#.#.###########.#.###.#.#.#######.###.#.#
|
|
||||||
#...#...#.#.#..w#.#.#.#.....#...#.....#.#.#.......#.....#.#...#.#.#.D...#.....#.#
|
|
||||||
#C#######.#.#.#.#.#.#.###.#.###.#####.#.#.#######.#.#####.#.###.#.#.###.#######H#
|
|
||||||
#......o..#...#...#.......#...#.A.....#.#.........#r......#.....#.....#.........#
|
|
||||||
#################################################################################
|
|
@ -1,3 +0,0 @@
|
|||||||
#########
|
|
||||||
#b.A.@.a#
|
|
||||||
#########
|
|
@ -1,5 +0,0 @@
|
|||||||
########################
|
|
||||||
#f.D.E.e.C.b.A.@.a.B.c.#
|
|
||||||
######################.#
|
|
||||||
#d.....................#
|
|
||||||
########################
|
|
@ -1,5 +0,0 @@
|
|||||||
########################
|
|
||||||
#...............b.C.D.f#
|
|
||||||
#.######################
|
|
||||||
#.....@.a.B.c.d.A.e.F.g#
|
|
||||||
########################
|
|
@ -1,9 +0,0 @@
|
|||||||
#################
|
|
||||||
#i.G..c...e..H.p#
|
|
||||||
########.########
|
|
||||||
#j.A..b...f..D.o#
|
|
||||||
########@########
|
|
||||||
#k.E..a...g..B.n#
|
|
||||||
########.########
|
|
||||||
#l.F..d...h..C.m#
|
|
||||||
#################
|
|
@ -1,6 +0,0 @@
|
|||||||
########################
|
|
||||||
#@..............ac.GI.b#
|
|
||||||
###d#e#f################
|
|
||||||
###A#B#C################
|
|
||||||
###g#h#i################
|
|
||||||
########################
|
|
@ -1,7 +0,0 @@
|
|||||||
#######
|
|
||||||
#a.#Cd#
|
|
||||||
##...##
|
|
||||||
##.@.##
|
|
||||||
##...##
|
|
||||||
#cB#Ab#
|
|
||||||
#######
|
|
@ -1,7 +0,0 @@
|
|||||||
###############
|
|
||||||
#d.ABC.#.....a#
|
|
||||||
######...######
|
|
||||||
######.@.######
|
|
||||||
######...######
|
|
||||||
#b.....#.....c#
|
|
||||||
###############
|
|
@ -1,7 +0,0 @@
|
|||||||
#############
|
|
||||||
#DcBa.#.GhKl#
|
|
||||||
#.###...#I###
|
|
||||||
#e#d#.@.#j#k#
|
|
||||||
###C#...###J#
|
|
||||||
#fEbA.#.FgHi#
|
|
||||||
#############
|
|
@ -1,9 +0,0 @@
|
|||||||
#############
|
|
||||||
#g#f.D#..h#l#
|
|
||||||
#F###e#E###.#
|
|
||||||
#dCba...BcIJ#
|
|
||||||
#####.@.#####
|
|
||||||
#nK.L...G...#
|
|
||||||
#M###N#H###.#
|
|
||||||
#o#m..#i#jk.#
|
|
||||||
#############
|
|
@ -1 +0,0 @@
|
|||||||
109,424,203,1,21102,11,1,0,1105,1,282,21101,0,18,0,1105,1,259,2101,0,1,221,203,1,21102,1,31,0,1105,1,282,21102,1,38,0,1105,1,259,20102,1,23,2,21201,1,0,3,21102,1,1,1,21102,57,1,0,1106,0,303,2102,1,1,222,21002,221,1,3,20101,0,221,2,21101,0,259,1,21101,0,80,0,1105,1,225,21101,44,0,2,21102,91,1,0,1105,1,303,1202,1,1,223,21002,222,1,4,21102,259,1,3,21102,1,225,2,21102,225,1,1,21101,118,0,0,1106,0,225,21002,222,1,3,21101,163,0,2,21101,0,133,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21102,148,1,0,1106,0,259,1202,1,1,223,20101,0,221,4,21001,222,0,3,21102,1,24,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21101,195,0,0,105,1,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21102,1,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2101,0,-4,249,22102,1,-3,1,22101,0,-2,2,22101,0,-1,3,21102,250,1,0,1106,0,225,21202,1,1,-4,109,-5,2105,1,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22102,1,-2,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21202,-2,1,3,21101,0,343,0,1106,0,303,1106,0,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,384,0,0,1105,1,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21202,1,1,-4,109,-5,2105,1,0
|
|
113
inputs/20p.txt
113
inputs/20p.txt
@ -1,113 +0,0 @@
|
|||||||
G R U E Z S S
|
|
||||||
W N C K Z G D
|
|
||||||
#################################.###########.###.#######.#########.#.#######.#####################################
|
|
||||||
#.#.......#.#.........#.#.#.....#.#.....#.#.#...#.....#.........#.....#...#.#...........#.......#.....#.....#.#...#
|
|
||||||
#.#####.###.###.###.#.#.#.###.###.#.###.#.#.###.#.###.###.#####.#.###.###.#.###.#########.###.###.#######.###.#.###
|
|
||||||
#.#.#.#...#...#.#.#.#.................#.#...#...#.#.#...#.#.....#.#.#.#.....................#.#.......#.........#.#
|
|
||||||
#.#.#.#.###.#####.#########.###########.#.#.#.###.#.#######.###.#.#.#####.###.#.###.#.###.#.###.#######.#######.#.#
|
|
||||||
#...#...#.#.#.#.........#...#...#.......#.#...#.......#.....#.#.#.....#.....#.#...#.#.#...#.#...#.#.........#.#.#.#
|
|
||||||
#.#.###.#.#.#.#####.#.#.#######.#.#######.###.#.###.#####.###.#####.#.###.#########.#.#.#######.#.#####.#####.#.#.#
|
|
||||||
#.#...#.#.#.#.#.....#.#.................#.#...#.#.#.....#...#.#.#...#...#.#.....#.#.#.#...#.#.#...........#.#.....#
|
|
||||||
###.###.#.#.#.#.#.#####.#.###.#########.#.#######.#.#####.###.#.#.#.#####.#.#.###.#.#######.#.#.###.#######.###.#.#
|
|
||||||
#...#.......#...#.#.#.#.#...#.#.........#.....#.......#.#.......#.#...#.....#.....#.#...#.........#...#.#.#.#.#.#.#
|
|
||||||
###.#######.#######.#.###########.#.#####.###.#####.###.#.#####.#.###.#.#.###.#.#######.###.#####.#####.#.#.#.#####
|
|
||||||
#.......#.#...#.......#.........#.#.#...#.#.#.#.....#.....#...#.#...#.#.#.#...#...#...#...#...#.#.#...........#.#.#
|
|
||||||
#.#.###.#.#.#########.#########.#.###.###.#.#####.#.###.#.#.#.#.#.###########.#.###.###.###.###.###.###.#.#####.#.#
|
|
||||||
#.#...#.....#.#...#.#.#.#.#.............#.....#...#...#.#.#.#...#...#.#.#.....#.........#...#.......#...#...#...#.#
|
|
||||||
###########.#.#.###.#.#.#.#######.#####.#.#####.#.#######.#####.###.#.#.#####.#.#.###.#####.###.#############.#.#.#
|
|
||||||
#.#.#.#.#.....#.#.....#.#.#.#.....#...#.#.....#.#.....#...#.#.#...#...#.#.#...#.#...#...#...#...#...#.#.......#.#.#
|
|
||||||
#.#.#.#.###.###.#####.#.#.#.#####.#.###.#.#########.#######.#.#.###.###.#.#.###.###.#####.#####.#.###.#####.#####.#
|
|
||||||
#.#...#.#...#.#.#...#...#.#.....#.#.....#.#...#.....#.......#.#.#...#.....#.#.#.#.......#.......#...#.#.#...#.#...#
|
|
||||||
#.#.#.#.###.#.#.###.#.###.#.#####.#.###.#.###.###.###.#.#.###.#.#.###.#.#.###.#.###.#####.#.#####.###.#.###.#.###.#
|
|
||||||
#.#.#.#.#...#.#...#...#.#.#...#...#...#.#.#.....#.#...#.#.#.....#.#...#.#.#.......#.......#...#.#.....#.........#.#
|
|
||||||
#.#.###.###.#.#.#####.#.#.#.###.#.#####.#.#.###.#.###.#.###.#.###.#.###.#####.#####.#####.#####.###.#########.#.#.#
|
|
||||||
#.....#...#.......#.#.#.......#.#.#...#.#...#.#.#.....#...#.#...#...#.#...#.......#...#.#...#...#...#.#.#.#.#.#.#.#
|
|
||||||
###.###.#######.###.#.#.#.#.#########.#.#####.#.#.#####.#######.#####.#.#####.#.#.###.#.#######.###.#.#.#.#.#.###.#
|
|
||||||
#.....#...#.#.#.......#.#.#.#.#.......#...#.....#.#.....#.......#.......#.#...#.#.#.#...#.....#.#.....#.#.#...#.#.#
|
|
||||||
###.###.###.#.#######.#.#####.#####.#.#.###.#########.#.###.#.#####.#####.###.#####.#######.###.###.###.#.#.###.#.#
|
|
||||||
#.....#.......#...#...#...#.#.#.#.#.#.#.#.......#.#...#.#.#.#...#.......#...#.......#...#.....#...#.#.........#...#
|
|
||||||
#.#####.#######.###.#.#.###.#.#.#.#.#.#.###.#.###.#.#####.#####.#####.#####.###.#######.###.###.###.#########.#.###
|
|
||||||
#...#...#...#.#.#...#.#.#.#.........#.....#.#.....#.......#.......#...#.............#...#...#.#.........#...#.#...#
|
|
||||||
#.###.###.###.#.#####.#.#.#.#####.#############.#######.#####.#####.#######.###########.###.#.###.#######.###.#.###
|
|
||||||
#...#...#...#...#.#...#...#.# S L B V G R #.#.#.#.....#.#.......#.#...#
|
|
||||||
#.###.#.#.#####.#.###.#.###.# D M E H X Q #.#.#.#####.#.###.#####.#.###
|
|
||||||
#.....#.#.................#.# #.........................#.#
|
|
||||||
#.###.###.#####.#.#.#.###.### #.#.#.###.#######.###.#.#.#.#
|
|
||||||
#.#.#.....#.#...#.#.#.#.....# RZ..#.#...#.....#.#...#.#.#.#..BE
|
|
||||||
#.#.#####.#.#####.#.#####.### #######.#####.#.#.#######.#.#
|
|
||||||
#.....#.#.....#.#.#.....#.#.# #.#.#.#.#.#...#.......#...#.#
|
|
||||||
###.###.###.#.#.#.#.###.#.#.# #.#.#.###.#####.#.#######.#.#
|
|
||||||
RI....#.....#.#.#...#.#.#.#....UW #.#.......#...#.#.#.#...#...#
|
|
||||||
#####.###############.###.### #.###.#####.#.#####.#.#.#####
|
|
||||||
#.....#.#.#...#.#.....#.#...# GW..........#.#.........#.#...#
|
|
||||||
#.###.#.#.#.###.###.###.##### #.###.#.#.###.#######.###.###
|
|
||||||
#...#...#.....#.#.......#....FM #.#...#.#.....#...#.........#
|
|
||||||
###.###.#.#.#.#.#.#########.# ###.#######.###.###########.#
|
|
||||||
AJ..#...#...#.#...#...#.....#.# #...#.#.#...#...#.#...#.#.#..GX
|
|
||||||
#.#.#########.#.#.#######.#.# #####.#.#######.#.###.#.#.###
|
|
||||||
#.....#.#.#.#.#.............# #...............#...#........DD
|
|
||||||
#######.#.#.###########.###.# ###.#######.###.#.#.#.#.###.#
|
|
||||||
#.....................#.#...# #.......#.....#...#.#.#.#...#
|
|
||||||
###.###.#.#.###.#####.####### #####.#########.###.#.###.###
|
|
||||||
GP..#...#.#.#.#.....#.#...#...# SG..#...#.....#...#.#.....#...#
|
|
||||||
#.###.#####.#.#.#.#.###.###.# #.#.###.#.#######.#######.###
|
|
||||||
#.#.....#.#.#.#.#.#.....#...# #.....#.#.#.#...#.#.#...#.#.#
|
|
||||||
#.#.#####.#########.#######.# #########.#.###.#.#.#.#####.#
|
|
||||||
#.....#...#..................SI DD....#........................UW
|
|
||||||
#.#######.#####.###.###.##### #.###.#####.#.###.#.###.#####
|
|
||||||
#.#.#...#...#.....#.#.#.#.#..AJ #.........#.#.#.#.#.#.....#.#
|
|
||||||
###.#.###.#.#########.###.#.# #.#####.###.#.#.#######.###.#
|
|
||||||
#.........#.#...#.....#.#.#.# #...#.....#.#...#.#.#.#.#....LM
|
|
||||||
#########.#.###.#.###.#.#.#.# #########.#.#.###.#.#.#####.#
|
|
||||||
AA......#.#.#.....#.#...#.....# #.#.#.#.#.#.#.#...#.#.#.....#
|
|
||||||
#.#####.#.#.###.#.#.###.#.### #.#.#.#.#########.#.#.#####.#
|
|
||||||
JO..........#...#...#.....#...# #.#.......#.#.............#.#
|
|
||||||
#####.###############.###.#.# #.#.#.#####.###.###.#.###.#.#
|
|
||||||
#.#.#...#.........#.#.#.#.#.# TX....#.............#.#...#...#
|
|
||||||
#.#.#######.#.#.#.#.###.###.# #.###.#.###.#####.###########
|
|
||||||
VH......#.....#.#.#.....#...#.# #.#...#.#...#...#.#.....#...#
|
|
||||||
#####.#.###########.###.##### #############.#####.###.#.#.#
|
|
||||||
#.....#.....#.#.......#.....# #.#...#...#.#.......#.#.#.#..RZ
|
|
||||||
#.#.#######.#.#######.#.##### #.###.###.#.###.#.###.#.#.###
|
|
||||||
#.#...........#.#............FW RN..#.....#...#.#.#.#.....#...#
|
|
||||||
#########.###.#.#.########### #.#.#.###.###.###.#.#####.###
|
|
||||||
#...#...#.#.....#.#.........# #...#.............#.......#.#
|
|
||||||
#.#.#.#################.#.#.# ###############.###########.#
|
|
||||||
AX..#...#.#...#.#...#...#.#.#..HR JO............#.#.#...........#
|
|
||||||
#.#.###.###.#.#.#####.###.#.# #.#.#####.#.#.###.#.#.#####.#
|
|
||||||
TX..#...#.......#...#.....#.#..EK #.#...#.#.#.......#.#...#.#..MM
|
|
||||||
###.#.###.#.#.#.#.###.#.#.### #.###.#.#######.#.###.###.#.#
|
|
||||||
#...#.....#.#...#.....#.....# #.#.#.....#.#...#...#.#.....#
|
|
||||||
#####.#.#.#####.###.#######.# R Y G U A M S #.#.#.#.###.#####.#.#.###.#.#
|
|
||||||
#.....#.#...#.....#.....#...# I Q P C X M Y #...#.#.#.....#...#.#...#.#.#
|
|
||||||
#####.#########.###.#####.###########.#####.###.###########.#####.###########.#.#######.#.###.#.#########.#.#####.#
|
|
||||||
#...#...#.#.......#.....#...#...#.....#.....#.....#.#.....#...#...........#...#...#...#.#.#.....#.#.......#.#.....#
|
|
||||||
#.#.#.###.###.#.#.#######.#####.###.###.###.#####.#.###.#.#.#########.#####.#####.#.#########.###.###.#####.###.#.#
|
|
||||||
#.#.......#...#.#.#.......#.....#.#.#.....#.#.....#...#.#.......#.#.#...#.......#.#.......#.#.#.#.....#.......#.#.#
|
|
||||||
#.#.#.#.#####.###########.#####.#.#.#.#.#.#####.###.###.#########.#.#.#######.###.#.#######.###.###.#.###.#.#.#.#.#
|
|
||||||
#.#.#.#...#.......#.......#.........#.#.#.....#.#.....#.........#.........#.#.#.....#.......#.......#.#.#.#.#.#.#.#
|
|
||||||
#######.#.#.#.#####.#.#########.#############.#.#.###.#######.#####.#.#####.#.#.#######.#####.#.#.###.#.#.#######.#
|
|
||||||
#.......#.#.#...#...#.#.........#.......#...#.#.....#.#.......#.....#...#.....#...........#.#.#.#.#.....#...#.....#
|
|
||||||
#.#.#.#####.#.#.#####.#.#######.#.###.###.###.#.###.#.#.###.#.#.#.###.#.#####.#.###.#.#.###.###.#.#.#.#####.#####.#
|
|
||||||
#.#.#.#.....#.#.#.....#...#.#.....#...#.......#.#...#.#...#.#.#.#...#.#.#.....#.#...#.#.......#.#.#.#...#.#.#.....#
|
|
||||||
#.###.###.#.###.###.#.#.###.#.#.#.#.###.###.#.#######.###.#.###.#######.#.#.#.#####.#.#.#.#############.#.#####.###
|
|
||||||
#.#.#.#.#.#...#.#...#.#.#.....#.#.#...#...#.#...#.....#...#...#...#.....#.#.#.....#.#.#.#.#.....#.#.#.......#...#.#
|
|
||||||
###.#.#.#.#.###.#####.#############.#.#.#.#.#######.###.###.###.#############.#####.#####.###.###.#.#.#####.###.#.#
|
|
||||||
#.......#.#.#.....#...#.#.......#...#.#.#.#.#.#.#.#...#...#.#.....#.#.#...#.....#.#.#...#...#.......#.....#...#...#
|
|
||||||
###.###.#.###.#########.#######.#####.#.#####.#.#.#.###.#######.###.#.#.#####.###.#.#.###.###.#####.#.#.###.###.###
|
|
||||||
#.....#.#.#.....#.....#.#.......#.#.#.#...#.......#.#.......#...#.....#.......#.........#.#.#.....#.#.#.#...#.....#
|
|
||||||
#.#####.#.###.#.#####.#.#######.#.#.#.#.#######.#.#.###.#####.#.###.#.###.#.#####.###.#####.#.#######.###.#.#.#.###
|
|
||||||
#.#.....#.#...#...#.......#.#.....#...#.#.#.....#...#.......#.#.....#.#...#...#.#...#...#.#.#.....#.#.#.#.#.#.#...#
|
|
||||||
#####.#.#.###.#######.#.###.###.#.#.###.#.#####.#######.#######.#.#####.###.###.###.#####.#.#.#####.###.#######.#.#
|
|
||||||
#.#.#.#.#.#.#.#...#...#...#.#.#.#...#.......#.#.....#.#.#...#...#.....#.#.......#.........#.#...#.#.........#.#.#.#
|
|
||||||
#.#.#######.#####.#####.###.#.#.#########.###.#####.#.#.#.#######.#########.#.###.#########.###.#.#.#########.#.#.#
|
|
||||||
#...#.#.#.#.....#.#...................#...#...#...#...#.....#...#.#...#...#.#.#.....#.#.......#.#.#.#.#.#.#...#.#.#
|
|
||||||
###.#.#.#.#.###.#.#####.#############.###.#.#.#.#.###.#.#.#####.#.#.#####.###.#.###.#.#####.###.#.#.#.#.#.###.#.###
|
|
||||||
#...........#.#.#...#...#.#.......#.#...#...#.#.#...#.#.#...#.#.......#.....#.#...#.#.#.#.#.....#.....#.#.....#...#
|
|
||||||
#####.#.#.#.#.###.#####.#.#.#.###.#.#.#######.#.###.#.#.###.#.#####.###.###.#.#.###.#.#.#.#.#####.###.#.#.#########
|
|
||||||
#.#...#.#.#.............#...#...#...#.....#...#...#...#.#.#.#...#...#...#.#...#.#...................#.............#
|
|
||||||
#.#####.#######.#.###.###.#.#.#####.#.#######.###.#####.#.###.#.#.#####.#.###.#.#.#####.###.#####.###.#.###.#.#####
|
|
||||||
#.......#.......#...#...#.#.#.#.........#.....#.....#.......#.#.......#.....#.#.#.....#...#.....#...#.#...#.#.....#
|
|
||||||
###################################.#######.###.#########.#######.#########.#######.###############################
|
|
||||||
Y S R S F F H
|
|
||||||
Q Y Q I M W R
|
|
@ -1,19 +0,0 @@
|
|||||||
A
|
|
||||||
A
|
|
||||||
#######.#########
|
|
||||||
#######.........#
|
|
||||||
#######.#######.#
|
|
||||||
#######.#######.#
|
|
||||||
#######.#######.#
|
|
||||||
##### B ###.#
|
|
||||||
BC...## C ###.#
|
|
||||||
##.## ###.#
|
|
||||||
##...DE F ###.#
|
|
||||||
##### G ###.#
|
|
||||||
#########.#####.#
|
|
||||||
DE..#######...###.#
|
|
||||||
#.#########.###.#
|
|
||||||
FG..#########.....#
|
|
||||||
###########.#####
|
|
||||||
Z
|
|
||||||
Z
|
|
@ -1,37 +0,0 @@
|
|||||||
A
|
|
||||||
A
|
|
||||||
#################.#############
|
|
||||||
#.#...#...................#.#.#
|
|
||||||
#.#.#.###.###.###.#########.#.#
|
|
||||||
#.#.#.......#...#.....#.#.#...#
|
|
||||||
#.#########.###.#####.#.#.###.#
|
|
||||||
#.............#.#.....#.......#
|
|
||||||
###.###########.###.#####.#.#.#
|
|
||||||
#.....# A C #.#.#.#
|
|
||||||
####### S P #####.#
|
|
||||||
#.#...# #......VT
|
|
||||||
#.#.#.# #.#####
|
|
||||||
#...#.# YN....#.#
|
|
||||||
#.###.# #####.#
|
|
||||||
DI....#.# #.....#
|
|
||||||
#####.# #.###.#
|
|
||||||
ZZ......# QG....#..AS
|
|
||||||
###.### #######
|
|
||||||
JO..#.#.# #.....#
|
|
||||||
#.#.#.# ###.#.#
|
|
||||||
#...#..DI BU....#..LF
|
|
||||||
#####.# #.#####
|
|
||||||
YN......# VT..#....QG
|
|
||||||
#.###.# #.###.#
|
|
||||||
#.#...# #.....#
|
|
||||||
###.### J L J #.#.###
|
|
||||||
#.....# O F P #.#...#
|
|
||||||
#.###.#####.#.#####.#####.###.#
|
|
||||||
#...#.#.#...#.....#.....#.#...#
|
|
||||||
#.#####.###.###.#.#.#########.#
|
|
||||||
#...#.#.....#...#.#.#.#.....#.#
|
|
||||||
#.###.#####.###.###.#.#.#######
|
|
||||||
#.#.........#...#.............#
|
|
||||||
#########.###.###.#############
|
|
||||||
B J C
|
|
||||||
U P P
|
|
@ -1,37 +0,0 @@
|
|||||||
Z L X W C
|
|
||||||
Z P Q B K
|
|
||||||
###########.#.#.#.#######.###############
|
|
||||||
#...#.......#.#.......#.#.......#.#.#...#
|
|
||||||
###.#.#.#.#.#.#.#.###.#.#.#######.#.#.###
|
|
||||||
#.#...#.#.#...#.#.#...#...#...#.#.......#
|
|
||||||
#.###.#######.###.###.#.###.###.#.#######
|
|
||||||
#...#.......#.#...#...#.............#...#
|
|
||||||
#.#########.#######.#.#######.#######.###
|
|
||||||
#...#.# F R I Z #.#.#.#
|
|
||||||
#.###.# D E C H #.#.#.#
|
|
||||||
#.#...# #...#.#
|
|
||||||
#.###.# #.###.#
|
|
||||||
#.#....OA WB..#.#..ZH
|
|
||||||
#.###.# #.#.#.#
|
|
||||||
CJ......# #.....#
|
|
||||||
####### #######
|
|
||||||
#.#....CK #......IC
|
|
||||||
#.###.# #.###.#
|
|
||||||
#.....# #...#.#
|
|
||||||
###.### #.#.#.#
|
|
||||||
XF....#.# RF..#.#.#
|
|
||||||
#####.# #######
|
|
||||||
#......CJ NM..#...#
|
|
||||||
###.#.# #.###.#
|
|
||||||
RE....#.# #......RF
|
|
||||||
###.### X X L #.#.#.#
|
|
||||||
#.....# F Q P #.#.#.#
|
|
||||||
###.###########.###.#######.#########.###
|
|
||||||
#.....#...#.....#.......#...#.....#.#...#
|
|
||||||
#####.#.###.#######.#######.###.###.#.#.#
|
|
||||||
#.......#.......#.#.#.#.#...#...#...#.#.#
|
|
||||||
#####.###.#####.#.#.#.#.###.###.#.###.###
|
|
||||||
#.......#.....#.#...#...............#...#
|
|
||||||
#############.#.#.###.###################
|
|
||||||
A O F N
|
|
||||||
A A D M
|
|
File diff suppressed because one or more lines are too long
100
inputs/22p.txt
100
inputs/22p.txt
@ -1,100 +0,0 @@
|
|||||||
cut 578
|
|
||||||
deal with increment 25
|
|
||||||
cut -3085
|
|
||||||
deal with increment 16
|
|
||||||
cut -6620
|
|
||||||
deal with increment 17
|
|
||||||
cut -1305
|
|
||||||
deal with increment 71
|
|
||||||
cut -4578
|
|
||||||
deal with increment 44
|
|
||||||
cut 5639
|
|
||||||
deal with increment 74
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 39
|
|
||||||
cut 7888
|
|
||||||
deal with increment 17
|
|
||||||
deal into new stack
|
|
||||||
cut 6512
|
|
||||||
deal with increment 46
|
|
||||||
cut -8989
|
|
||||||
deal with increment 46
|
|
||||||
cut -8518
|
|
||||||
deal with increment 75
|
|
||||||
cut -870
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 53
|
|
||||||
cut 7377
|
|
||||||
deal with increment 60
|
|
||||||
cut -4733
|
|
||||||
deal with increment 25
|
|
||||||
cut -6914
|
|
||||||
deal with increment 23
|
|
||||||
cut -4379
|
|
||||||
deal into new stack
|
|
||||||
cut 582
|
|
||||||
deal with increment 35
|
|
||||||
cut 9853
|
|
||||||
deal with increment 2
|
|
||||||
cut -142
|
|
||||||
deal with increment 74
|
|
||||||
cut 328
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 75
|
|
||||||
deal into new stack
|
|
||||||
cut -8439
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 34
|
|
||||||
cut 2121
|
|
||||||
deal with increment 2
|
|
||||||
cut 8335
|
|
||||||
deal with increment 65
|
|
||||||
cut -1254
|
|
||||||
deal into new stack
|
|
||||||
cut -122
|
|
||||||
deal with increment 75
|
|
||||||
cut -9227
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 24
|
|
||||||
cut 3976
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 8
|
|
||||||
cut -3292
|
|
||||||
deal with increment 4
|
|
||||||
deal into new stack
|
|
||||||
cut -8851
|
|
||||||
deal with increment 2
|
|
||||||
deal into new stack
|
|
||||||
cut 4333
|
|
||||||
deal with increment 73
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 9
|
|
||||||
cut -7880
|
|
||||||
deal with increment 49
|
|
||||||
cut 9770
|
|
||||||
deal with increment 30
|
|
||||||
cut 2701
|
|
||||||
deal with increment 59
|
|
||||||
cut 4292
|
|
||||||
deal with increment 37
|
|
||||||
deal into new stack
|
|
||||||
cut -184
|
|
||||||
deal with increment 25
|
|
||||||
cut 9907
|
|
||||||
deal with increment 46
|
|
||||||
deal into new stack
|
|
||||||
cut 902
|
|
||||||
deal with increment 46
|
|
||||||
cut 2622
|
|
||||||
deal into new stack
|
|
||||||
cut 637
|
|
||||||
deal with increment 58
|
|
||||||
cut 7354
|
|
||||||
deal with increment 69
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 49
|
|
||||||
deal into new stack
|
|
||||||
deal with increment 19
|
|
||||||
cut -8342
|
|
||||||
deal with increment 68
|
|
||||||
deal into new stack
|
|
@ -1,3 +0,0 @@
|
|||||||
deal with increment 7
|
|
||||||
deal into new stack
|
|
||||||
deal into new stack
|
|
@ -1,3 +0,0 @@
|
|||||||
cut 6
|
|
||||||
deal with increment 7
|
|
||||||
deal into new stack
|
|
@ -1,3 +0,0 @@
|
|||||||
deal with increment 7
|
|
||||||
deal with increment 9
|
|
||||||
cut -2
|
|
@ -1,10 +0,0 @@
|
|||||||
deal into new stack
|
|
||||||
cut -2
|
|
||||||
deal with increment 7
|
|
||||||
cut 8
|
|
||||||
cut -4
|
|
||||||
deal with increment 7
|
|
||||||
cut 3
|
|
||||||
deal with increment 9
|
|
||||||
deal with increment 3
|
|
||||||
cut -1
|
|
File diff suppressed because one or more lines are too long
@ -1,5 +0,0 @@
|
|||||||
.#.##
|
|
||||||
...#.
|
|
||||||
....#
|
|
||||||
.#...
|
|
||||||
..#..
|
|
@ -1,5 +0,0 @@
|
|||||||
....#
|
|
||||||
#..#.
|
|
||||||
#..##
|
|
||||||
..#..
|
|
||||||
#....
|
|
@ -1,5 +0,0 @@
|
|||||||
.....
|
|
||||||
.....
|
|
||||||
.....
|
|
||||||
#....
|
|
||||||
.#...
|
|
File diff suppressed because one or more lines are too long
47
main.go
47
main.go
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -27,10 +26,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
flagPart1 = flag.Bool("part1", false, "whether to run part1 or not; if no flags are present, all parts are run")
|
flagPart1 = flag.Bool("part1", false, "whether to run part1 or not; if no flags are present, all parts are run")
|
||||||
flagPart2 = flag.Bool("part2", false, "whether to run part2 or not; if no flags are present, all parts are run")
|
flagPart2 = flag.Bool("part2", false, "whether to run part2 or not; if no flags are present, all parts are run")
|
||||||
flagCpuProfile = flag.String("cpuprofile", "", "write cpu profile to file")
|
|
||||||
flagMemProfile = flag.String("memprofile", "", "write memory profile to file")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var dayMap = []day{
|
var dayMap = []day{
|
||||||
@ -51,30 +48,11 @@ var dayMap = []day{
|
|||||||
&days.Day15{},
|
&days.Day15{},
|
||||||
&days.Day16{},
|
&days.Day16{},
|
||||||
&days.Day17{},
|
&days.Day17{},
|
||||||
&days.Day18{},
|
|
||||||
&days.Day19{},
|
|
||||||
&days.Day20{},
|
|
||||||
&days.Day21{},
|
|
||||||
&days.Day22{},
|
|
||||||
&days.Day23{},
|
|
||||||
&days.Day24{},
|
|
||||||
&days.Day25{},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *flagCpuProfile != "" {
|
|
||||||
f, err := os.Create(*flagCpuProfile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
pprof.StartCPUProfile(f)
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
arg := strconv.Itoa(len(dayMap))
|
arg := strconv.Itoa(len(dayMap))
|
||||||
flagArgs := flag.Args()
|
flagArgs := flag.Args()
|
||||||
if len(flagArgs) > 0 && len(flagArgs[0]) > 0 {
|
if len(flagArgs) > 0 && len(flagArgs[0]) > 0 {
|
||||||
@ -99,14 +77,7 @@ func main() {
|
|||||||
solve(dayMap[iArg-1])
|
solve(dayMap[iArg-1])
|
||||||
}
|
}
|
||||||
|
|
||||||
if *flagMemProfile != "" {
|
os.Exit(0)
|
||||||
f, err := os.Create(*flagMemProfile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
pprof.WriteHeapProfile(f)
|
|
||||||
f.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func solve(d day) {
|
func solve(d day) {
|
||||||
@ -126,11 +97,6 @@ func solve(d day) {
|
|||||||
part1Text = d.Part1()
|
part1Text = d.Part1()
|
||||||
}
|
}
|
||||||
part1Time := time.Since(part1Start)
|
part1Time := time.Since(part1Start)
|
||||||
if runPart1 {
|
|
||||||
fmt.Println(part1Header)
|
|
||||||
fmt.Println(">", part1Text)
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
part2Start := time.Now()
|
part2Start := time.Now()
|
||||||
var part2Text string
|
var part2Text string
|
||||||
@ -138,12 +104,17 @@ func solve(d day) {
|
|||||||
part2Text = d.Part2()
|
part2Text = d.Part2()
|
||||||
}
|
}
|
||||||
part2Time := time.Since(part2Start)
|
part2Time := time.Since(part2Start)
|
||||||
|
|
||||||
|
if runPart1 {
|
||||||
|
fmt.Println(part1Header)
|
||||||
|
fmt.Println(">", part1Text)
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
if runPart2 {
|
if runPart2 {
|
||||||
fmt.Println(part2Header)
|
fmt.Println(part2Header)
|
||||||
fmt.Println(">", part2Text)
|
fmt.Println(">", part2Text)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(utilities.ColorBrightBlack)
|
fmt.Print(utilities.ColorBrightBlack)
|
||||||
fmt.Println("Parsed in", parseTime)
|
fmt.Println("Parsed in", parseTime)
|
||||||
if runPart1 {
|
if runPart1 {
|
||||||
|
@ -10,13 +10,3 @@ func ArrayContains[T comparable](array []T, val T) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddToArray[V comparable, T ~[]V](arr *T, val V) bool {
|
|
||||||
for _, v := range *arr {
|
|
||||||
if v == val {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*arr = append(*arr, val)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package utilities
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Bisect takes a known-good low and known-bad high value as the bounds
|
|
||||||
// to bisect, and a function to test each value for success or failure.
|
|
||||||
// If the function succeeds, the value is adjusted toward the maximum,
|
|
||||||
// and if the function fails, the value is adjusted toward the minimum.
|
|
||||||
// The final value is returned when the difference between the success
|
|
||||||
// and the failure is less than or equal to the acceptance threshold
|
|
||||||
// (usually 1, for integers).
|
|
||||||
func Bisect[T Number](low, high, threshold T, tryFunc func(val T) bool) T {
|
|
||||||
for T(math.Abs(float64(high-low))) > threshold {
|
|
||||||
currVal := low + ((high - low) / 2)
|
|
||||||
success := tryFunc(currVal)
|
|
||||||
if success {
|
|
||||||
low = currVal
|
|
||||||
} else {
|
|
||||||
high = currVal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return low
|
|
||||||
}
|
|
@ -28,8 +28,6 @@ type IntcodeProgram struct {
|
|||||||
program []int64
|
program []int64
|
||||||
relativeBase int
|
relativeBase int
|
||||||
haltRequested bool
|
haltRequested bool
|
||||||
printASCII bool
|
|
||||||
feedInput []rune
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntcodeProgramState struct {
|
type IntcodeProgramState struct {
|
||||||
@ -130,27 +128,20 @@ func (p *IntcodeProgram) ensureMemoryCapacity(address int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *IntcodeProgram) Reset() {
|
func (p *IntcodeProgram) Reset() {
|
||||||
wiped := false
|
p.memory = nil
|
||||||
if len(p.memory) != len(p.program) {
|
|
||||||
wiped = true
|
|
||||||
p.memory = nil
|
|
||||||
}
|
|
||||||
p.init()
|
p.init()
|
||||||
if !wiped {
|
copy(p.memory, p.program)
|
||||||
copy(p.memory, p.program)
|
|
||||||
}
|
|
||||||
p.relativeBase = 0
|
p.relativeBase = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *IntcodeProgram) Run() int64 {
|
func (p *IntcodeProgram) Run() {
|
||||||
return p.RunIn(func(int) int64 { return 0 }, func(int64, IntcodeProgramState) {})
|
p.RunIn(func(int) int64 { return 0 }, func(int64, IntcodeProgramState) {})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *IntcodeProgram) RunIn(inputFunc ProvideInputFunc, outputFunc ReceiveOutputFunc) int64 {
|
func (p *IntcodeProgram) RunIn(inputFunc ProvideInputFunc, outputFunc ReceiveOutputFunc) {
|
||||||
p.init()
|
p.init()
|
||||||
|
|
||||||
inputsRequested := 0
|
inputsRequested := 0
|
||||||
lastOutput := int64(0)
|
|
||||||
for instructionPointer := 0; instructionPointer < len(p.program) && !p.haltRequested; {
|
for instructionPointer := 0; instructionPointer < len(p.program) && !p.haltRequested; {
|
||||||
instruction := p.GetMemory(instructionPointer)
|
instruction := p.GetMemory(instructionPointer)
|
||||||
instructionPointer++
|
instructionPointer++
|
||||||
@ -187,28 +178,13 @@ func (p *IntcodeProgram) RunIn(inputFunc ProvideInputFunc, outputFunc ReceiveOut
|
|||||||
case opInput:
|
case opInput:
|
||||||
inputsRequested++
|
inputsRequested++
|
||||||
param1 := p.GetMemory(instructionPointer)
|
param1 := p.GetMemory(instructionPointer)
|
||||||
var inputVal int64
|
p.setMemory(int(param1), inputFunc(inputsRequested), paramModes[0])
|
||||||
if len(p.feedInput) > 0 {
|
|
||||||
inputVal = int64(p.feedInput[0])
|
|
||||||
p.feedInput = p.feedInput[1:]
|
|
||||||
} else {
|
|
||||||
inputVal = inputFunc(inputsRequested)
|
|
||||||
}
|
|
||||||
if p.printASCII && inputVal <= 255 {
|
|
||||||
fmt.Printf("%c", rune(inputVal))
|
|
||||||
}
|
|
||||||
p.setMemory(int(param1), inputVal, paramModes[0])
|
|
||||||
|
|
||||||
instructionPointer += 1
|
instructionPointer += 1
|
||||||
|
|
||||||
case opOutput:
|
case opOutput:
|
||||||
param1 := p.GetMemory(instructionPointer)
|
param1 := p.GetMemory(instructionPointer)
|
||||||
param1Val := p.getParamValue(int(param1), paramModes[0])
|
outputFunc(p.getParamValue(int(param1), paramModes[0]), p.makeState(instructionPointer))
|
||||||
if p.printASCII && param1Val <= 255 {
|
|
||||||
fmt.Printf("%c", rune(param1Val))
|
|
||||||
}
|
|
||||||
outputFunc(param1Val, p.makeState(instructionPointer))
|
|
||||||
lastOutput = param1Val
|
|
||||||
|
|
||||||
instructionPointer += 1
|
instructionPointer += 1
|
||||||
|
|
||||||
@ -274,19 +250,8 @@ func (p *IntcodeProgram) RunIn(inputFunc ProvideInputFunc, outputFunc ReceiveOut
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.haltRequested = false
|
p.haltRequested = false
|
||||||
|
|
||||||
return lastOutput
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *IntcodeProgram) Stop() {
|
func (p *IntcodeProgram) Stop() {
|
||||||
p.haltRequested = true
|
p.haltRequested = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *IntcodeProgram) SetDebugASCIIPrint(enable bool) {
|
|
||||||
p.printASCII = enable
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *IntcodeProgram) FeedInputString(str string) {
|
|
||||||
p.feedInput = make([]rune, len(str))
|
|
||||||
copy(p.feedInput, []rune(str))
|
|
||||||
}
|
|
||||||
|
@ -15,13 +15,3 @@ func MapValues[T comparable, U any](m map[T]U) []U {
|
|||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyMap returns a copy of the passed-in map. Note: currently only works if [U]
|
|
||||||
// is not a map or slice.
|
|
||||||
func CopyMap[T comparable, U any](m map[T]U) map[T]U {
|
|
||||||
r := make(map[T]U)
|
|
||||||
for k, v := range m {
|
|
||||||
r[k] = v
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
@ -44,16 +44,11 @@ func (v Vec2[T]) Equals(other Vec2[T]) bool {
|
|||||||
v.Y == other.Y
|
v.Y == other.Y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Vec2[T]) ManhattanDistance(other Vec2[T]) T {
|
|
||||||
return T(math.Abs(float64(v.X-other.X)) + math.Abs(float64(v.Y-other.Y)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func VecBetween[T Number](a, b Vec2[T]) Vec2[T] {
|
func VecBetween[T Number](a, b Vec2[T]) Vec2[T] {
|
||||||
return a.To(b)
|
return Vec2[T]{
|
||||||
}
|
X: a.X - b.X,
|
||||||
|
Y: a.Y - b.Y,
|
||||||
func ManhattanDistance[T Number](a, b Vec2[T]) T {
|
}
|
||||||
return a.ManhattanDistance(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v Vec3[T]) Dot(other Vec3[T]) T {
|
func (v Vec3[T]) Dot(other Vec3[T]) T {
|
||||||
|
Reference in New Issue
Block a user