2023 Day 10 Complete!

This commit is contained in:
Brian Buller 2023-12-10 10:26:21 -06:00
parent 433a4414b6
commit be17b84517
8 changed files with 656 additions and 0 deletions

140
2023/day10/input Normal file
View File

@ -0,0 +1,140 @@
F.F77.F7F7FFJJ..77FF.--L777.-7777--F7F7FJFFF7FF|.F77FF|-7-|-F7-7-FF|FJ-FFJ7-F--F|-L--7L|-7FFFF---7-FJ.7J.F-7J.F|7-LF7L7|.F-L|7...LF--LL7F-77
|77FL-F7F-FJJF7FJ-FJF.L||FLJF7JFJ7FJ77LJ-7-||L77-F-7||L7|LL.JJ.L-FFJ-|.FJJ|F|FJJ|..|-7.77LLJF7JJ-|7L77J|.|L|-L7|L-|LL-L7-|7.L7F7-FLJ|FFLJ-LJ
JFFJJFF-|J.|L7.7FL|7|7.LL-J.-JF||J|-L|7|FL7L7FJ|.--7|F---.L-J.|-7JL-F7-7--|7L7.7.F.-JL7L|J.F-JJJ7LFJJLL7F|-7.LF-7.F7LF|L-LFLJL-7FJL|-|7|7.FJ
LLJ7LJL7||FF-|-J7J||--7J7.FJL7-.F-J.|..F7L|FF|J77LFFLFJL|F7|FLJLFFJ-J7.LJ|L|FJ-F7J.LF|--JF--7|L||7.|JJ|LFJF7J-7.|.|J-|-JFFJ|J7|L|--F.--F77.7
LLLJL|-7-7-|-F7-77.JJ.|-F-7J||L-F7.|.7-L|7JFLJLJ|.7--|7JL.FJJJ-F.L.7F-7JF7J|JL|LJ-..F7|7.F-LL-FF-|7J|FLJ|.J.FFF7F7JJLF.|F7LL.F|7L7-|7JJJLF.L
F|F|F||L.|L7|||FJ|7L--JFL7L-|-7.7--JJ|LLJ7LFJ.LL|.LJFLL7.F.|7F-LJJ-JLLJ.|7J|LLF7J.|7|L-77|-JLF7J7LJF-77F|.||7.F7||.|.L-|-|.FFFJJ7JFLF7-F|J.|
-77.|J7|-7.L-J7L-F77L|J77LFLL||F|7FF7|..|J.L-L-.L7L|L7FL77.-7L7J||.F-LJ-JJ.|7||L-.FFL-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JLJF--J|F-JF--77FF-JF--7F7
7J7.||FJL-JL-7.FJL-J|L7LJ||L7|F-J|7L--7FJLJLJFJ||F-7||F7L-7L-7|F7F7|F-JFJ|||L---7LL-JF-----JF-7LJ|L---7|L-7|||||F-7F7L---JL--JF-JJ-7J-L|-F-J
LF|-LLL-7F7F7|FJF7F7||L-7|L-JFJF7|F---J|F-7F-J.LJ|FJ||||F7|F-JLJ||||L7FJ-||L7F--JF---JF--7F7|FJF-J|F7JLJLFJLJLJLJFJ|L--------7L-7J|JLF7|7.FJ
|FJL|JLLLJLJ|LJFJ||||F--JL---JFJLJL----JL7|L--7.FJL-JLJLJ|LJF7FFJ|LJFJL-7||FJL-7FJF7F7L77LJLJL-JFF-JL----J|F-7F77L7L----7F--7|F-JLJ7FFJ|LFJ|
F|7|F7F|LF7LL--J7LJLJL--7F7F7FJF----7F7F7|L7F-JFJF7F7F---JF7|L7L7|F7L-7FJLJ|F7FJL7||||FJF-------7|F7F-----7|FJ|L77L-7F--J|F-J||7LFFF7|F-LL-|
FL--J--F-J|F-------7F---J||||L7L-7F7LJ||LJ-LJF7|FJLS||F7F7|LJFJL|LJ|F7|L--7||||F-J||||L7L----7F7|||LJF----J|L7|FJF7||L---JL-7|L77-JF|7|LL|7|
|7L|.|LL-7LJF-7F--7LJF7F7|LJL-JF7LJL-7|L-7F7FJLJL-7FJ||||LJF7|F7L--J|LJF7FJLJ|||F7|LJ|FJF--7|||||LJF-JF----JFJ|L-JL7L---7F7FJL7L-7FFLJ.F.|-J
LL--77LLFJF7|-LJF-JF-JLJLJ-F7FFJL-7F-J|F-J|||F----JL-J|LJF-JLJ||.F7|L7FJLJLLFJ|LJLJF7||FJF7L-J||L7FL--JF---7L-JF7F-JF7F7LJLJF7L--JJ||-|-7J7|
F|LLJJF.L7|||F-7L--JF7F7F7FJL7L--7|L-7|L-7|||L-7F7|F7FJF7L7F7FJ|FJL-7||-L7..|FJ|F7-|LJ||FJ|F--J|FJF7|F7L--7L-7FJ|L--JLJL----JL---7.||LF-L7J7
-|F|7-7FL||||L7L----JLJ|||L-7|FF7|L--J|F-J|||F-J|L7|||FJL-J|||FJL7F-JLJ|JF--LJF-J|.L7FJLJFJ|F7FJL-JL-JL---JF7LJFJF-7F---7F----7F-JF7-7J7||.J
F77.JJLJLLJLJ-L-------7||L--JL-JLJF--7LJF7||||F7|FJ|||L-7F7||||F7|L-77FF-7.FLLL-7|F7LJF77L-J||L-7F7F7F----7|L7LL7|FJL--7|L---7|L7.FJF7||-|7J
FLJ7LF-||.F7LF--------JLJF-7F---7FJF-JF-JLJLJLJLJL-J||F-J|||LJLJLJF7L--JFJ7F|.F-JLJ|7FJL7F7FJL-7||LJ||F---J|FJF7LJL-7F-J|F7F-J|FJ.|L7-J||LJ.
LJFJ|.FF-FJL-JF-7F7F7F-7FJFJ|F--J|LL7FJF--7F--7F---7LJL--JLJF7F7F-JL7F--JF77.FL-7F7L7L7FJ||L-7FJLJF7LJL--7FJL-JL---7|L-7LJ|L-7||F--FJ|FF7-|7
JFF.L-7J7L----JFJ|||LJFJL7L-JL7F7|F-J|FJF7|L-7|L--7L7F---7F7|||LJ||FJL---JL77F7-LJL7L-J|FJL--J|F7FJ|F----JL7F------J|F7L-7L--JLJ-7.J---.-7L7
J7J7.|J7FF-----JFJLJF7L7FJ.F7|LJLJL--JL7||L--JL---JL|L--7|||||L-7F7|F-7F---J-JF.JLLL--7||F---7LJ|L7|L--7F--JL-----7LLJL--JF--7LL7F--7-|7|||L
||L7-LJ|7L------JF--JL7LJF-J|F--------7LJL7|F7F--7F7L---JLJ|||F7LJ|LJJLJ.JLL|-JJ7JF7F7||LJLF-JF7L-JL7F7LJF---7F---JF---7F-JF7||||JLFFJ|LFF-J
FFLJF|FF--------7L---7|F7L-7|L-----7F7L7F-JFJLJF-J||LF---7.LJLJL-7|LL7|.7J|FF-F|7.|||||||F7L-7|L7F-7LJ|F7L--7LJF---JF-7LJF7|LJ7F|-FJJFL7LL.L
|J|FL7FL-----7F7L7F--JLJL--JL------J|L7|L--JF-7L--JL-JF-7L------7LJ|7F-7L.LFJF----JLJLJL7||F7LJJLJJL-7LJL---JF7|F---J|L7FJLJJLJF|-|L||7J.|FL
||F|JL7J|F-7FLJL7|L-7F--------------JFJ|F-7FJLL7F-7F--JLL-----7FJJFL-FJ77F-L-|F--------7||||L7F7F----JF------JLJL--7F-7|L---7|||L7|--|--7-L.
F-J|7JJ.FL7L7F--J|F7||F--------------J|LJJ|L--7LJ-|L---7F----7||7F|FL|J-L77|FLJF-------JLJ||FJ||L---7FJF-----------J|FJL---7L--7L-J7FJ|J|..J
|.|-J7...LL7LJF-7LJ|LJL---7F----------7F-7|F-7L--7L7F-7LJF7F-J|L7F-7F|-7-7LL-F-JF7F7F-7F-7LJL-JL--7LLJFJF7F7F----7FFJL----7L---J|..77--777-L
FF-.|7FJ7JLL7FJ-|F7L7FF---J|F7F7F-7F--J|FJLJ-L-7FJ|||FJF7||L-7L7LJFJ-F7L7|-.|L-7|LJLJJLJ.L-7F-7F-7|F7-L-JLJLJF7F7L-JF-----JF7F7F|F--J-JL-F7.
F7.F7FJ|7.FF||F-J|L7L-JF--7||LJ|L7|L---J|F7F7F7LJF7LJL7|||L--J.|F-J7|J|FLJJ7F--J|J|FF------J|FJ|FJLJ|F7LF-7F7|LJL---JF7F7F7|||L-77.|-|L7.|L7
FF7.L|.LLF--J|L7FJLL-7FJF-J||F7L-JL----7LJLJLJL-7|L--7|||L---7-||J-LJJF|JJLFL---J.F7L7F--7F7|L-JL--7LJL7L7LJ||F7F7F7FJLJLJLJLJF7L77JF|||.|FJ
F..F-|-|LL-7FJLLJFF--JL7|F7|LJL7F7F---7|F----7F-J|F-7||||F---JLLJ||.FFF7F7.F-7LF7FJL-J|F7LJLJF7LF--JF-7L-JF7|LJLJLJLJF--------JL-JL|-J-F-F||
|-F7F|-JFF7LJF7F-7L----JLJLJLF7LJLJF--J|L---7|L--J|-LJLJ||F-7J.|.FJFF7|LJL7L7|.|||F-7FJ|L--7FJ|FJF-7|FJF--J||F------7L--7F7LF7JL|-F7-|-7.LJJ
|..|7|7F7|L7|||L7|F-------7F-JL----JF7FL----J|F7F7L7F7F7LJ|FJ|.L7|LFJ|L--7|FJL7||||FJL7L--7|L7|L-JFLJL7|F--JLJF7F--7L--7LJL-JL7FF77|.L.L.|..
J7----F-7L7|FJL-JLJF-----7LJF7F-----JL-7F-7F7LJLJL-J|LJL--JL--7.LFFL7L7F7|LJF7|||LJL-7|F--JL7||F7|F7F7LJL7F77FJ||F-JF-7L7F7F--JFJL-7-|7L----
.F-|7JL7L-JLJF7F7F-JF----JF7||L7F------JL7LJL-7F7.F-JF--------JFF.LLL7LJ||F-JLJ|L7LF7LJ|F7F7LJLJL7|LJ|F-7||L-JFJ|L-7L7L7LJ|L-7LL7F-JF-7FLJ-L
JLFJ||.|F7F7FJLJ|L-7L7F7F7|||L-JL7F7F----JF---J|L7|F-JF------7F7F77-FJF7LJ|F7F7|FJL|L-7LJLJ|F7F-7|L7FJL7|LJF-7L-JF-JFJFJF7L--JF-JL--JFJ-.77.
FJJFF7FLJLJLJ.F7L--J7LJLJ||LJF7F7LJLJF----JF7F7L7LJL--JF--7F7||LJL7FJFJ|F-J|||||L-7L7FJF-7FJ|||FJL-JL--JL--JLL7F7|F-JFJFJL---7L7F----J.|.L|7
F|F|L|7J|-LF--J|LF7F7F-7FLJF7|LJL----JF---7|LJ|FJF-7F7FJF7LJ|||F--JL7|FJ|F7|LJLJF-JFJL7L7|L-JLJL------7F----7FJ||LJF-JFJF----JFJL----7F--FF-
.77L-F--J7LL--7L-JLJ||FJF77||L------7FJF7FJ|F-J|FJ.|||L7|L7|LJ||F7||LJL7LJ||F--7L-7L-7L-J|F------7F7F7LJF---JL7||F7L-7L7L-----JF-----JJJ-L.|
.L7JJ|.FJF|F7FJF---7LJL-JL-JL-------J|FJ|L-JL7J||F7LJL7|L7L7LFJLJ|F7.F7|F-J||F7L--JF7L--7||F----7||LJL77L----7|||||F7|FJF-----7L-----7J|7.F|
FL-7-7-J7F7|||FJF7FJF----7F--7F------J|LL7F-7L-JLJL--7||LL7L7L7F-J||FJLJL7||LJL-7F7||F--J|LJF---JLJF-7L------J||LJLJ|LJFJF7F7.L7F-7F7|.L---J
L7LJ.|.|F|LJLJ|FJLJFJF---J|F-J|F7F7F-7L-7LJFJF7F7F---JLJF7L7L-JL-7||L---7L7L7F--J||||L7F7L--JF----7L7L7F-----7|L--7FJF7L-JLJL7|LJFLJ|L7JFLF|
|JF-FFL|7L----JL-7FJFJF7F-JL--J|||LJ|L--JF7L-JLJ||F---7FJ|FJF----J||F--7|FJL|L-7FJ|||JLJL---7L7F--JFJFJ|F----JL---JL-JL7F7F-7L-7F7F7L-J77F||
F7L-J|.FF7F7LF---J||L-J||F-----JLJF--7F--JL----7|||F--JL7|L7L---7F||L-7LJL7FJF-JL7LJ|F7F----JFJL7F-JLL-JL--7F7F--7F---7||LJ7|F7LJLJL-7-7||-|
FL--L|-||LJL-JF---JF7F-J|L7F------JF7LJF7F7F---JLJ||F-7FJ|FJF--7|FJL7FJF-7||FJ-F7L-7LJ|L7F-7FJF7||F-7|F----J||L7FJ|F--J|L7F7LJ|F-7F7FJJJ7|F7
|7J|L7.FL-----J.F7FJLJF7L7LJF------JL--JLJLJF----7|LJFJL7|L7|F7LJL7FJL-JFJLJ|F7||F7|F7|FJ|FJ|FJLJ|L7L-JF-7F7||FJL-J|F-7L7LJL-7|L7LJ||JJFFF7J
-77LF---.LF7F---JLJF7FJL-JF7L---------------JF7F-J|F-JF7||L||||F7FJL7F-7L--7||||LJLJ|LJL-JL-JL-7FJ|L7F7|FJ|||LJF--7LJFJL|F7F-JL7L7FJ|J-LJL||
.LJ7|.LLJJ|LJF---7FJLJF---JL--------7F7F7F7F-JLJF-J|F7|||L-JLJ||||F-JL7|.F7|LJLJF7F-JF-7F-7F---J|F-7LJLJL-JLJF7L-7L7FJF7LJLJF-7L-JL-J.L|--J7
.|-F-7F-J-L-7|F--J|F7.L--7F----7F7F7LJLJ|||L---7L-7|||||L--7F7LJLJL7F7||FJLJF---JLJF7|FJL7|L---7|L7L-7-F7F---JL-7L7|L-JL---7L7L-777-J--|J.F|
FLF||JLJJFFFJ|L---J||F7F7LJF--7LJLJL---7LJL7F7FJF7|||LJ|F-7LJ|F----J|||||F-7|7F7F7L||||F7||F-7FLJFJF-JFJLJF7F7F7L-JL---7F--JJ|F-JF7FJ7||7FF|
J|LLJ.7JF7FL-JFF--7||||||F7L-7|F7F7F--7L--7LJLJ|||||L-7||FJF-JL---7J||||LJFJL7|LJ|FJ||LJ|||L7|F7FJFJF7L---JLJLJL----7F7|L--7FJL7FJL7.|7LJ--J
L7-LJ.J.-|-LF-7L-7LJLJLJLJL--JLJLJ|L-7|F--JF-7-FJ||L7||LJL7L-7F---JFJLJ|LFJF7LJF-J|FJ|F-J||FJ||LJFJ-||.F7F7F7F7F----J||L---JL-7LJF7|-JJ.LJJ.
FJL|-|.FL|7LL7|F7L--------7F7F7F-7L--JLJ|F7L7|FJFJ|FJFJF--JF7|L---7L--7L7L-J|F-JF7|L-JL-7||L7|L-7|F7||FJLJLJ||LJF7F--JL---7F7-|F-JLJ7F.F7|LF
JJ-7-JF-7L77FJLJ|F-------7LJLJLJ7L-7F7LF7|L7|||FJFJL7L7L7F-J||F---JF7LL7L7LFJL--J|L-7F--J||FJL7L||||||L---7FJL--J|L7F-----J||FJL7F7|F77-F-.|
|F-|.LL7|-J7L--7LJF7F---7L---7F---7LJ|FJLJFJ|LJL7L-7|F|FJ|F-J|L-7F7||F7|FJFJF----JF7|L7FFJ||F-JFJLJ|||F7F-JL7F7F7L-JL-7|F7FJLJF7LJ|FJ|J-7.F7
F|-|-.F--JLFF--JF7|LJ.F7L---7|L-7FJF-JL-7FJ7L--7|F7||FJL7|L7FJF-J|||||LJL7|FJF7FF7||L7L7L7|||F7L7F-J||||L7F7LJLJL-----JFJLJF7FJ|F7LJFJJ7L--7
F|7|.-F7L7LLL---JLJJF7||F---JL--JL-JF7F7||F-7F7|LJ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|7L-J7J7F||.F|.-F.|FJF--|77-LL7J|.FFF--J|||F7|F|7LJ-||F-7L-JFF--J||L-7|||L7LJ.|||.|7|-LFL.FJF--J.||L7L7FJF-J7J.|JLF--7.|L|.F|.FL|7
----L7J7LFL77.L7-JJ|77FFJ-F7|FLJ7LF-L7|JL7L--F|F7FJ|LJL---7JLFLJJLL7F--JF7FJL7FJLJL-J7|7LF7F|JL-7|FFL-JJ7LL||L|FJ|FJJ|L7.7.F|7JJ-F--LJ.FFJLL
L7L-7J-7F-7FL--JJ.LF.FFL-|L-|-JF7LLLJ|L--JJFFJLJLJ-|F-7F7FJ.L-7J|LLLL---J||7L||LL7F|J|LLJL|----L|||J7J-LJ.L||.|L7|||FFJFJ-|-7-----77L77|...|
|F7JLJJF|--|||.J-7-J--7JFJ7.-7LJ77||-LFJ-7--||L|J7.|L7LJ||--J|F.|..|L|JF|LJ7L||-7LLJF7-L77L-J-77F|||7JFFFJ7LJ-L-JLJF-|F|F||..|-..F-7-||L----
FJ||LLF-77.-|LF|-L.||LL.7JFL.F-L-7-L-.L.F-FJ.FFJJF-L-JJFJL7JFFL-|-L-7|.F7FJJ-LJ7L77.L-F-LL7JF--||LJJ--F-7L|JLLL-FJJF-|-F|-.-LL-77|.7.J-|..||
FL--7.LLJ-JL7-FFJLF-J-|-F-7J-F.L|.|LJ---L-L7.-FJJL7JL..L--J-|L|.7--L|L-FJ|JJ-L.L-L-F-L|-LL7-JJ.LLFJ-|LLJLJ.JJLJ77J--.-.LL--JLJL|-LLJ7JL-J.-7

168
2023/day10/main.go Normal file
View File

@ -0,0 +1,168 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
m, l := part1(inp)
fmt.Println()
part2(m, l)
}
const (
NS = '|'
EW = '-'
NE = 'L'
NW = 'J'
SW = '7'
SE = 'F'
START = 'S'
)
var pipes = []byte{NS, EW, NE, NW, SW, SE}
func part1(input []string) (h.CoordByteMap, []h.Coordinate) {
m := h.StringSliceToCoordByteMap(input)
_, loop := findLoop(&m)
fmt.Println("# Part 1")
fmt.Println(len(loop) / 2)
return m, loop
}
func part2(m h.CoordByteMap, loop []h.Coordinate) {
var insideCoords []h.Coordinate
var inside bool
var enclosed int
for y := m.TLY; y <= m.BRY; y++ {
inside = false
var rowPathStart byte
for x := m.TLX; x <= m.BRX; x++ {
wrk := h.Coordinate{X: x, Y: y}
wrkV := m.Get(wrk)
if h.CoordListContains(wrk, loop) { //&& (wrkV == NS || wrkV == NE || wrkV == NW) {
// This coordinate is part of the loop, so it can change the 'inside' flag
// A corner _only_ changes the flag if the 'exiting' corner continues in the same direction
// i.e.: L--J doesn't change the flag, L--7 does change the flag
switch wrkV {
case NE, SE:
rowPathStart = wrkV
case NW, SW:
if continues(rowPathStart, wrkV) {
inside = !inside
}
}
if wrkV == NS {
// a | always changes the flag
inside = !inside
}
} else {
if inside {
enclosed++
insideCoords = append(insideCoords, wrk)
}
}
}
}
fmt.Println("# Part 2")
fmt.Println(enclosed)
for _, insides := range insideCoords {
m.Put(insides, 'I')
}
}
// continues checks if two _corner_ pieces continue the flow in the same direction
func continues(p1, p2 byte) bool {
switch p1 {
case NE:
return p2 == SW
case NW:
return p2 == SE
case SW:
return p2 == NE
case SE:
return p2 == NW
}
return false
}
func connectsNorth(v byte) bool {
return v == START || v == NS || v == NE || v == NW
}
func connectsSouth(v byte) bool {
return v == START || v == NS || v == SE || v == SW
}
func connectsEast(v byte) bool {
return v == START || v == EW || v == NE || v == SE
}
func connectsWest(v byte) bool {
return v == START || v == EW || v == NW || v == SW
}
func connects(m *h.CoordByteMap, p1, p2 h.Coordinate) bool {
p1v, p2v := m.Get(p1), m.Get(p2)
switch {
case p1.North().Equals(p2):
return connectsNorth(p1v) && connectsSouth(p2v)
case p1.East().Equals(p2):
return connectsEast(p1v) && connectsWest(p2v)
case p1.South().Equals(p2):
return connectsSouth(p1v) && connectsNorth(p2v)
case p1.West().Equals(p2):
return connectsWest(p1v) && connectsEast(p2v)
}
return false
}
func countConnections(m *h.CoordByteMap, p h.Coordinate) int {
var res int
for _, tst := range []h.Coordinate{p.North(), p.East(), p.South(), p.West()} {
if connects(m, p, tst) {
res++
}
}
return res
}
// Find loop finds all coordinates on the loop and returns:
// 1. The starting coordinate
// 2. All coordinates on the loop
// It also replaces the 'S' for the starting coordinate with the appropriate
// pipe byte
func findLoop(m *h.CoordByteMap) (h.Coordinate, []h.Coordinate) {
start, _ := m.FindFirst(START)
next := start
path := []h.Coordinate{start}
// Figure out the starting pipe byte
for _, v := range pipes {
m.Put(start, v)
if countConnections(m, start) == 2 {
break
}
}
for {
for _, tst := range []h.Coordinate{
next.North(),
next.East(),
next.South(),
next.West(),
} {
if !connects(m, next, tst) || (!tst.Equals(start) && h.CoordListContains(tst, path)) {
continue
}
next = tst
}
if next.Equals(start) {
// We're done
return start, path
} else {
path = append(path, next)
}
}
}

310
2023/day10/problem Normal file
View File

@ -0,0 +1,310 @@
[1]Advent of Code
• [2][About]
• [3][Events]
• [4][Shop]
• [5][Settings]
• [6][Log Out]
br0xen [7](AoC++) 20*
        //[8]2023
• [9][Calendar]
• [10][AoC++]
• [11][Sponsors]
• [12][Leaderboard]
• [13][Stats]
Our [14]sponsors help make Advent of Code possible:
[15]Kotlin by JetBrains - Jingle bells, Kotlin pals, coding all the way!
Solve puzzles, catch our daily livestreams for expert guidance, embrace
the joy of Kotlin, and engage with a fantastic community. Happy holidays
and happy coding!
--- Day 10: Pipe Maze ---
You use the hang glider to ride the hot air from Desert Island all the way
up to the floating metal island. This island is surprisingly cold and
there definitely aren't any thermals to glide on, so you leave your hang
glider behind.
You wander around for a while, but you don't find any people or animals.
However, you do occasionally find signposts labeled "[16]Hot Springs"
pointing in a seemingly consistent direction; maybe you can find someone
at the hot springs and ask them where the desert-machine parts are made.
The landscape here is alien; even the flowers and trees are made of metal.
As you stop to admire some metal grass, you notice something metallic
scurry away in your peripheral vision and jump into a big pipe! It didn't
look like any animal you've ever seen; if you want a better look, you'll
need to get ahead of it.
Scanning the area, you discover that the entire field you're standing on
is densely packed with pipes; it was hard to tell at first because they're
the same metallic silver color as the "ground". You make a quick sketch of
all of the surface pipes you can see (your puzzle input).
The pipes are arranged in a two-dimensional grid of tiles:
• | is a vertical pipe connecting north and south.
• - is a horizontal pipe connecting east and west.
 L is a 90-degree bend connecting north and east.
 J is a 90-degree bend connecting north and west.
 7 is a 90-degree bend connecting south and west.
 F is a 90-degree bend connecting south and east.
• . is ground; there is no pipe in this tile.
 S is the starting position of the animal; there is a pipe on this
tile, but your sketch doesn't show what shape the pipe has.
Based on the acoustics of the animal's scurrying, you're confident the
pipe that contains the animal is one large, continuous loop.
For example, here is a square loop of pipe:
.....
.F-7.
.|.|.
.L-J.
.....
If the animal had entered this loop in the northwest corner, the sketch
would instead look like this:
.....
.S-7.
.|.|.
.L-J.
.....
In the above diagram, the S tile is still a 90-degree F bend: you can tell
because of how the adjacent pipes connect to it.
Unfortunately, there are also many pipes that aren't connected to the
loop! This sketch shows the same loop as above:
-L|F7
7S-7|
L|7||
-L-J|
L|-JF
In the above diagram, you can still figure out which pipes form the main
loop: they're the ones connected to S, pipes those pipes connect to, pipes
those pipes connect to, and so on. Every pipe in the main loop connects to
its two neighbors (including S, which will have exactly two pipes
connecting to it, and which is assumed to connect back to those two
pipes).
Here is a sketch that contains a slightly more complex main loop:
..F7.
.FJ|.
SJ.L7
|F--J
LJ...
Here's the same example sketch with the extra, non-main-loop pipe tiles
also shown:
7-F7-
.FJ|7
SJLL7
|F--J
LJ.LJ
If you want to get out ahead of the animal, you should find the tile in
the loop that is farthest from the starting position. Because the animal
is in the pipe, it doesn't make sense to measure this by direct distance.
Instead, you need to find the tile that would take the longest number of
steps along the loop to reach from the starting point - regardless of
which way around the loop the animal went.
In the first example with the square loop:
.....
.S-7.
.|.|.
.L-J.
.....
You can count the distance each tile in the loop is from the starting
point like this:
.....
.012.
.1.3.
.234.
.....
In this example, the farthest point from the start is 4 steps away.
Here's the more complex loop again:
..F7.
.FJ|.
SJ.L7
|F--J
LJ...
Here are the distances for each tile on that loop:
..45.
.236.
01.78
14567
23...
Find the single giant loop starting at S. How many steps along the loop
does it take to get from the starting position to the point farthest from
the starting position?
Your puzzle answer was 6942.
--- Part Two ---
You quickly reach the farthest point of the loop, but the animal never
emerges. Maybe its nest is within the area enclosed by the loop?
To determine whether it's even worth taking the time to search for such a
nest, you should calculate how many tiles are contained within the loop.
For example:
...........
.S-------7.
.|F-----7|.
.||.....||.
.||.....||.
.|L-7.F-J|.
.|..|.|..|.
.L--J.L--J.
...........
The above loop encloses merely four tiles - the two pairs of . in the
southwest and southeast (marked I below). The middle . tiles (marked O
below) are not in the loop. Here is the same loop again with those regions
marked:
...........
.S-------7.
.|F-----7|.
.||OOOOO||.
.||OOOOO||.
.|L-7OF-J|.
.|II|O|II|.
.L--JOL--J.
.....O.....
In fact, there doesn't even need to be a full tile path to the outside for
tiles to count as outside the loop - squeezing between pipes is also
allowed! Here, I is still within the loop and O is still outside the loop:
..........
.S------7.
.|F----7|.
.||OOOO||.
.||OOOO||.
.|L-7F-J|.
.|II||II|.
.L--JL--J.
..........
In both of the above examples, 4 tiles are enclosed by the loop.
Here's a larger example:
.F----7F7F7F7F-7....
.|F--7||||||||FJ....
.||.FJ||||||||L7....
FJL7L7LJLJ||LJ.L-7..
L--J.L7...LJS7F-7L7.
....F-J..F7FJ|L7L7L7
....L7.F7||L7|.L7L7|
.....|FJLJ|FJ|F7|.LJ
....FJL-7.||.||||...
....L---J.LJ.LJLJ...
The above sketch has many random bits of ground, some of which are in the
loop (I) and some of which are outside it (O):
OF----7F7F7F7F-7OOOO
O|F--7||||||||FJOOOO
O||OFJ||||||||L7OOOO
FJL7L7LJLJ||LJIL-7OO
L--JOL7IIILJS7F-7L7O
OOOOF-JIIF7FJ|L7L7L7
OOOOL7IF7||L7|IL7L7|
OOOOO|FJLJ|FJ|F7|OLJ
OOOOFJL-7O||O||||OOO
OOOOL---JOLJOLJLJOOO
In this larger example, 8 tiles are enclosed by the loop.
Any tile that isn't part of the main loop can count as being enclosed by
the loop. Here's another example with many bits of junk pipe lying around
that aren't connected to the main loop at all:
FF7FSF7F7F7F7F7F---7
L|LJ||||||||||||F--J
FL-7LJLJ||||||LJL-77
F--JF--7||LJLJ7F7FJ-
L---JF-JLJ.||-FJLJJ7
|F|F-JF---7F7-L7L|7|
|FFJF7L7F-JF7|JL---7
7-L-JL7||F7|L7F-7F7|
L.L7LFJ|||||FJL7||LJ
L7JLJL-JLJLJL--JLJ.L
Here are just the tiles that are enclosed by the loop marked with I:
FF7FSF7F7F7F7F7F---7
L|LJ||||||||||||F--J
FL-7LJLJ||||||LJL-77
F--JF--7||LJLJIF7FJ-
L---JF-JLJIIIIFJLJJ7
|F|F-JF---7IIIL7L|7|
|FFJF7L7F-JF7IIL---7
7-L-JL7||F7|L7F-7F7|
L.L7LFJ|||||FJL7||LJ
L7JLJL-JLJLJL--JLJ.L
In this last example, 10 tiles are enclosed by the loop.
Figure out whether you have time to search for the nest by calculating the
area within the loop. How many tiles are enclosed by the loop?
Your puzzle answer was 297.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should [17]return to your Advent calendar and try
another puzzle.
If you still want to see it, you can [18]get your puzzle input.
You can also [Shareon [19]Twitter [20]Mastodon] this puzzle.
References
Visible links
1. https://adventofcode.com/
2. https://adventofcode.com/2023/about
3. https://adventofcode.com/2023/events
4. https://teespring.com/stores/advent-of-code
5. https://adventofcode.com/2023/settings
6. https://adventofcode.com/2023/auth/logout
7. Advent of Code Supporter
https://adventofcode.com/2023/support
8. https://adventofcode.com/2023
9. https://adventofcode.com/2023
10. https://adventofcode.com/2023/support
11. https://adventofcode.com/2023/sponsors
12. https://adventofcode.com/2023/leaderboard
13. https://adventofcode.com/2023/stats
14. https://adventofcode.com/2023/sponsors
15. https://kotlinlang.org/
16. https://en.wikipedia.org/wiki/Hot_spring
17. https://adventofcode.com/2023
18. https://adventofcode.com/2023/day/10/input
19. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Pipe+Maze%22+%2D+Day+10+%2D+Advent+of+Code+2023&url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F10&related=ericwastl&hashtags=AdventOfCode
20. javascript:void(0);

5
2023/day10/testinput1 Normal file
View File

@ -0,0 +1,5 @@
-L|F7
7S-7|
L|7||
-L-J|
L|-JF

5
2023/day10/testinput2 Normal file
View File

@ -0,0 +1,5 @@
7-F7-
.FJ|7
SJLL7
|F--J
LJ.LJ

9
2023/day10/testinput3 Normal file
View File

@ -0,0 +1,9 @@
...........
.S-------7.
.|F-----7|.
.||.....||.
.||.....||.
.|L-7.F-J|.
.|..|.|..|.
.L--J.L--J.
...........

10
2023/day10/testinput4 Normal file
View File

@ -0,0 +1,10 @@
.F----7F7F7F7F-7....
.|F--7||||||||FJ....
.||.FJ||||||||L7....
FJL7L7LJLJ||LJ.L-7..
L--J.L7...LJS7F-7L7.
....F-J..F7FJ|L7L7L7
....L7.F7||L7|.L7L7|
.....|FJLJ|FJ|F7|.LJ
....FJL-7.||.||||...
....L---J.LJ.LJLJ...

View File

@ -184,3 +184,12 @@ func GetHighestX(list ...Coordinate) int {
} }
return top return top
} }
func CoordListContains(needle Coordinate, haystack []Coordinate) bool {
for _, chk := range haystack {
if chk.Equals(needle) {
return true
}
}
return false
}