2023 day 10
This commit is contained in:
parent
bfcad28fff
commit
a9fc4c9e60
3
2023/10/go.mod
Normal file
3
2023/10/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module git.tristans.cloud/tristan/aoc/2023/10
|
||||
|
||||
go 1.21.4
|
140
2023/10/input.txt
Normal file
140
2023/10/input.txt
Normal file
|
@ -0,0 +1,140 @@
|
|||
F-7JF-F-F|-J.FL|.L-L7.L-L-J.7F-FJ-F7F.F7J-F.J.7.FF7L-7F7|7FFF7FF7FF7.L7J-77FF-7-|-|7.7.J7J7F--J7..FL-F.JFJ.-7F-F7F77-L--F.FF77-7FFLJ-.F|J.F7
|
||||
|F-J||L-.J7.|..F7.LL7J.-L|.LL-J|J-|JJF7J.FF-7.F.-L7JL|.7.L|-|77F.||-7-|J|FJ7L|JLL7JLF7-F---7JLJ7-F-J|.FFJL||L|7L|-FJ7...77LJ-7FFLJ||.LJ|7F|7
|
||||
FF-77-7L7FF77F--J77|.||FLF7-|.|L-FJ|||JFLFJL7-F.FL|.LLJ|.|J.L-FJF77-7.L--JJ|.F--F-F7-J---7J.-7|L-7.||JF-7JF7JL7JJ.|-J7.-JJ|JFF|.L|J|F|FL|F-7
|
||||
F7-J|FJ.---|JJ7L.FFL7FF7FL-7L|7-LJ7F7JF|FJ-LL7-|7LL-JLLJ.LFL-F|7F|-F--.LJJ|FL7-FLJ|FF.|.F|-FFJ-FF7L-7FLJL-LL--JJ7.77|7.|.L7LFL-7J.LJJLJ7L7J|
|
||||
||FJ7F7FL7L7.LJJ.L-.|77L7|||7L-J|JL-J--JL77.||LJ|.|7-77|.LLL.LJLJLF7.|F.L|F-7.F||F-LJ--77|.FJ..LJ-J-J77-|-||.L|.L7LL|.F7-J|7F7|J|7F-|-F|7LLL
|
||||
F77.-FJJLJF|7||.FLL7..--L|-7JLJ7FJ|-|7FJFF|7L7|L|7F|F|F7-..|77.7.F-J.LJ7FF7-F7F777L|F77.F7.||LJ.||.|FFL-JF-L7.|J-F.F7-L||.|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J|L--J|LJ|-L7L-JF-J|||LJL-7FJLJL7FJ|-FJ|.FLF.|-7JL7J7
|
||||
J-L|||F7LLFF-------J||||FJF7L-7F-JFJL7LL7L-J|F7F7L-7L7|||F-JL7||FJFJ||||FJFJL-J|||L7FJL7|F7JFJF7|F7L7F7L7FJLJF---J|F---J|FJ-L7|F7.|..L7LF77|
|
||||
FF.7J-F77LFJF7F--7F7LJ||L7||-FJL-7L--JF7|F--J||||F-JFJ||||FF7|LJL7L7LJ||L7|F--7||L-JL--J||L7L-J|||||||L-J|F--JF7|FJL7F7FJL77FJLJL777.LLF|L||
|
||||
JJ-JFF||7-L7|LJF7LJL-7|L7|||FJF7FJ7F7FJLJL7F7||||L7FJFJ|||FJLJF7FJJL-7||FJLJF-JLJF------J|FJF7FJ|||FJL7F7|L-7FJL7|F-J||L7FJFJF-7FJ7.F.|FJFF|
|
||||
||-LF-||F7JLJLFJL-7F7|L7|||LJFJLJF7||L--7FJ||||||FJL7|FJ||L-7FJLJF-7FJLJL7F7L7F--J|F7JF7F|L7||L7|||L7FJ|||F-J|F-J||F7|L-JL-JFJFJL7|FJFFJ|FLJ
|
||||
--F-|||||L7LF7L--7|||L7LJ||F-JF7-||||F7L|L7|LJLJLJF-J|L7||.FJL---JFJL7F-7|||FJ|F7F7|L7||FJFJ||L||||FJL7|||L-7||7FJ|||L7F7F7FJFL--JJJF----JJL
|
||||
.|JJLF|LJFJFJL7F7||||LL-7|||F-J|FJLJ|||FJFJL-----7|F7L7|||FJF-----JLFJ|FJ||||FJ|||||FJ||L7|FJ|FJ|||L7FJ|||F-J|L7|FJ|L7||LJLJF--7JL7FLJJJLFFJ
|
||||
FL-J--L-7|-L-7LJLJ||L7F7||||L-7||F--J|||FJF7F7F--J|||J||||L7L-7F7F-7L-JL7|||||FJLJ||L7||FJ|L7||FJ||FJL-JLJL-7L7||L7|FJ|L7F--JF7|JF--7|7F-|.|
|
||||
FJJL-LF-J|JF7L---7|L7LJLJ|||F7||||F-7||||FJ|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L7|L7||F-JL--7LFJF7|||FJFJLJF-J|L7FJL-7F7|FJ|L7F7F7F-7|L7|F7F-7F7L-7|L-7L--7|7JFL|LFF
|
||||
FFF---7-||LFL7|||||F7F--JL-7F--JL--JL---JF7JFJFJFJ|FJ|L-J|FJLJL7F7F-JFJFJ||||L7L--7L--J|LJJF-J|LJL7L-J|||||FJL-JLJLJ|LJL7FJ|F7L7F7|L7.|J|.F-
|
||||
-JL7--L7L-.FLLJFJ|FJLJF----JL---------7F7|L7L7|7L7||FJF7FJL--7-LJLJ7FJFJFJ|||||F-7L-----7F7L--JF-7L---JLJ|||F7-F7F7F-7F7LJFJ|L7LJ|L-J-J|J|..
|
||||
|LLLJ7-J|F|7-F7L7LJF--J.F77F7F--------J|||FJ-||F7||LJJ||L----JF-----JFJFJFJ||FJL7L7F7F7FJ||F7F-JFJF7F7F7LLJLJL-JLJLJFJ|L7JL7|7|F-JJLFL7FF.LL
|
||||
7-|.-77-|-LF-JL-JF-J-F--JL-JLJF-7F----7||||F7|||LJ|F--JL--7JF7L----7FJJL7L7|||F7|FJ|LJLJ7||||L-7|FJLJLJL7F----7F7F7FJFJFJF7|L7|L7|LF|7L-L.|J
|
||||
.-7F||L7L-FL-7F7FJF--JF-7F7F7FJFJ|F---J|LJLJ||||F7LJF-7F-7L7|L-----JL7F-JFJ||||||L7L-7LF7|LJL--JLJF7F7F7LJF7F7LJLJ|L-JFJ|||L-J|FJ7-FJ-|-|7--
|
||||
LF7F|||L-F||.LJLJJ|F-7L7LJLJ||FJFJL---7|F---JLJ|||F7|FJL7L7||F-7F-7F-JL-7L7LJLJ||FJF-JFJLJF7F7F7F-JLJLJL--JLJL---7|F--J|FJL--7|L7|F-7FLLFJJ7
|
||||
.F7FL7-7-JL|7LLF--JL7L-JFF-7LJL-JF--7FJ|L-----7LJ||LJL7FJ7||||FJ|FJL-7F7|FJFF--J|L7L-7|F7FJLJLJ||F----7F-------7FJ||F7F7L7F--JL-J-JF|7FJ|LL7
|
||||
-LJJLL7|LJFL7-|L----JF---JFJ.F7F-JF7LJF|F-----JJFJL-7FJL-7||||L7|L7F7LJ|LJF-JF7FJ-L7FJLJLJF7F--J|L---7|L-----7|LJFJLJLJL-JL-7||||7.JJFFFJ77L
|
||||
FJ|.JFFLJ|LJ|7-F----7L---7L--JLJF-JL---JL--7F7F7L-7FJL-7FJLJ||FJ|FJ||F7L-7|F-J||F7FJL---7FJLJF--JF---JL-----7L--7L-7F-7F7F-7L7F7-|7FJ-FJ-JL.
|
||||
|.L7JFF|-7FL||FL7F-7L-7F7L------J|F----7F--J||||F7LJF7FJL-7FJ|L7|L7|||L--JLJJFJ||LJF-7F-JL--7|F-7L---------7L7F-JFFJL7LJLJ|L-J|L7|LJ.L|7L7J|
|
||||
L7-7-F-FF-JF-J-7LJFJF7LJL----7F7F7L---7|L---JLJLJL--J||F--JL-JJLJFJ||L--7F7LFJFJ|F7L7||F---7LJL7L---------7L7|L--7L--JF7F7-F--JFJ7.LJ-L|.LF7
|
||||
FL.J.7|JL.JJ7LLJJJL-JL------7||LJL--7FJL----7F7F-----J|L-7|F7-F--JFJL7F7LJL7|FJFJ||FJLJL--7|.F7L-7F7F-7F-7L-JL---JF7F7|LJL-JF--JFF77J.7J7|FL
|
||||
-.F7LLL7|77FL7FL.|F7F7F--7F7|||F---7LJF----7LJ|L----7FJF7L7||FJF-7L-7|||F7FJ|||L7||L-7F-7FJL7||JFJ|LJ|LJJL------7F|||LJF7F7FJF7FFJL-7-7FJ7J|
|
||||
F77-JJF-LJJ7FL7FF-J|||L-7LJLJ|LJF7JL-7|F---JF7|F----JL7|L7LJ||FJ-|F7|||||LJ7LJF-J||F7|L7LJF7LJ|FJFJF------------JFJ||F-J|||L-JL-JF7FJ7JFF|L7
|
||||
F-JLJF|J-|-||F7-L-7LJL-7L-7F7L--J|F--J|L----J||L-----7LJJ|F-J|L-7LJ||LJ|L---7FL-7|||||FJF-JL-7LJFJ.L7F-----7F-7F-JFJ|L-7LJL-7F7F7|||JL-F|L77
|
||||
FJ77.-J7.|FLJ7.F7F|F7F7L7|LJL---7|L--7|F----7|L-7F--7L--7|L7FJF7L7FJL-7L7F-7|F--J|LJ||L7|F---JF7|-F-J|F----J|FJL-7L-JF7L---7LJ||LJLJL|.J..L-
|
||||
|F-JJJ-|-LL.F7F|L-J|LJL7|F7F7F--JL---J|L---7LJF7LJF7L-7FJ|FJL7|L7|L7F-JFJL7||L7F7L-7||LLJL-7F7||L7L--JL-----JL-7-|F-7|L7F-7L-7LJJ-F---7JFJ7J
|
||||
-F-JJ|-L7.F-7F7L---JFF7|||LJ|L7F-7F7.FJF--7|F-JL--J|F7|L7|L7FLJ.LJL||F-JF7|LJ-LJ|F-JLJJF---J|LJ|FJF-------7F7F-JFJL7|L7|L7|F-JJJFFL7F-JFJJ||
|
||||
.|7JFF--L--LFJL------JLJLJF7L-J|FJ|L-JFJF7LJ|F-----J||L-J|FJF----77|||F7|||.F---JL7F--7L-7F7L7FJ|LL7F7F7F7LJLJJFJF-JL-JL7|LJLF7-F-7||JJ7-7-F
|
||||
.L|L7L||LJ7|L---7F7F7F7F7FJL7F-JL-JF-7L7|L-7|L-----7|L7F7LJJ|F-7FJ-LJLJ||LJFL7F-7FJ|F7L--J||FJL7|F7LJLJLJL-7|F7|FJFF7LF7LJF--J|FJFJ||7JJL|J.
|
||||
F-JFJJ||.LFJ-F--J|LJ||LJLJF7LJF----J7L-J|F-J|F-----J|FJ||F7F|L7LJ..LJ.F|L7|FFJ|-|L7LJ|F7F7||L7FJ||L-------7L7|LJL--JL-JL-7|F--JL7|7|||L--LJL
|
||||
FLFJ7.-L--77.L-7FJF7LJF7F-JL--JF-7F----7||F7|L-77F--JL-JLJL7|FJF|-7LJ-FJFJ-FL-JFJFJF7||LJ|||FJL-JL-------7L7LJF----------J|L--7FJL-JL7...L.|
|
||||
|.|7|7L7LFJFF77LJFJL-7||L------J7LJF---J|||||F-JFJF7F7F7F-7LJL--7-7-J7|FJ.|L|7LL-J|||LJF7LJLJF-7F7F7LF---JFL--JLF7F--7F7F-JF--JL7F--7|7-F.FL
|
||||
F7FFL-|JFLF-J|F7FJF-7|||F7FF--7F7F7L----JLJLJ|F7|FJLJLJLJLL7F---J.||LFLJJ7LLLJFF---JL7L||F7F7L7LJLJL7|F7F--7F---JLJF7||LJF-JF7F7||F7LJ-7-FFJ
|
||||
-FJL-7F-7-|F7LJLJFJFJLJLJL7L-7||LJ|F7F7F7F7F7LJLJL7F-----7FJL----7|F-FJ7LJ.|-FLL--7F7L7||||||.L----7LJ|LJF7LJF7F7F7|LJ|F-JF7|LJLJLJL7LJJ-LFJ
|
||||
|L|J.||7.|LJ|F7F-JLL----7FJF7||L-7||LJLJ|||||F7F--J|F----JL7F--7FJ-J-L7JJ-7..7|.|-||L7LJLJLJ|F7F---JF7|F-JL--JLJ|||L7FJL--JLJF-7F--7L7F|FLLF
|
||||
-7LFF-7-FJJLLJ||F---7F--JL7||||F7||L---7|||||||L7F7|L7F-7F7|L-7|L-7|FFJFFF-77FF--FJL7L-7F--7|||L----JLJL-------7LJL7LJF7F7F-7L7|L-7L7L7.LJ7|
|
||||
LFFL|J-7LJ-|||||L--7|L---7LJLJLJLJL----J||||||L7LJLJFJ|FJ||L7FJL7FJ-7LJ-FJ-F|LF7LL--JF7LJF-JLJL----------------JF7-L7FJLJLJFJFJL7FJ7L-J--LJJ
|
||||
FLF7L.L7|7-LF-LJF--JL----JF-7F---------7LJ||LJFJF-7FJFJL-JL7LJ7.|L7.F77.L7F-J|LJ77LF-JL--JF-7F-7F------7F--7F-7FJL-7|L-7F7FL-JF7LJLJ.|.|7-|7
|
||||
77|F-J-LJ-JLJ.|LL7F-7F7F--JF||F-----7F7L7F||F7L7L7|L-JF---7L7-7FL-JFJ|-7L7L|.|J7||-L7F7F-7L7LJFLJF7F--7LJF-J|FJL7F-JL-7LJL----JL-7|J.L----J|
|
||||
--|F7FF-JJF-.F--7LJ.LJ||F--7LJL7F7F7LJL7L7|LJL7L7||F--JLF7L-JLL|7LFJFJJ|7|-L7J7|F7J-||LJFL7|F----J|L-7L-7|F-JL7FJ|F7F7L----7F-7F7|-7.L|LL.F|
|
||||
|7|LL7|FL-JJ7L-7|F7FF7LJL-7|F7JLJLJL7F7L-J|F7FJ-|||L-S--JL--7.F-7FJFJJ||F7-LJFLF-7.|LJF-7FJ|L----7L--JF7LJ|F-7LJFJ|||L-7JF7LJJLJLJ.FFFJ.FFFJ
|
||||
L7LJ.L|7|J|FF-FJLJL-JL--7FJ|||F77F7FJ||F7JLJ||F7LJ|F7F-7F7F7|FJFJL7L-777JLF-||-L7|.FF7L7||FJ7F--7L-7F-JL--JL7L7FJL|||F-JFJL-----7L7-|LF7F7J7
|
||||
F7JF7.JJJF77F7L7F7F--7F7|L7LJLJL-J|L-JLJL7FFJLJL-7|||L7LJLJLJL7L--JF7|L-7.||F|.L|L--JL-J|LJF-JF7L--J|F7F7F7FJFLJF-JLJL--JF7F7F--JF7|F-7JF|J|
|
||||
|7F||F7JF-LFJL-J|||F-J||L-JF7F---7L---7F7L7L7F7F7|||L7L--7F7F7L-7F-JLJ7.|.FL7L-||F7F--7FJF7L--JL7F-7||LJLJLJF---JF-------JLJLJ-F-JL7--L-7|L7
|
||||
||L-FJFFJ|LL----JLJL--JL-7FJ||F--JF-77LJL7||LJLJ||LJL|F-7LJ|||F-JL-7JF77FFF.|7.LLJLJF-JL-JL-----J|JLJL------JF7F7L--7F------7F7|F--J7LL7JL7|
|
||||
LLJ7.FFJFF---------7F7F7FJL7LJL7F7|FJF7F7|L---7J|L--7|L7|F7||LJF---J.||L-J|.F7FLF--7L-----7F-----JF----------JLJL--7LJF-----J||||JF-7-7LFJ--
|
||||
.|L77||L-L7F7F7F7F7LJLJLJF7|F--J|LJL-JLJ|L7F-7L7|F--J|FJ||LJL-7|F-7F-J|JJ.F7|L7.L-7L----7.LJF---7-L----------7F7F-7L--JF7F--7|||L-JFJL--|LFJ
|
||||
.-7F.FL.J.LJ||LJLJL--7F-7|||L7F7|F------JL||FJFJLJF7-LJJLJF---JLJFJ|F-JJ.F|||FJ-F7L----7|F7|L--7|F7F7F7F-----J|LJFJF7F-JLJF-J|||F--JJ.|||.|J
|
||||
F.FL7FLJ7LF-J|F-7F7F7LJJLJLJLLJ|||F7.F---7|||FJF7FJ|F-7F7FL----7FJF|L77JF7|LJ|JFJL7F---JLJL7F7FJLJLJ||LJF--7F7L-7L7|||F7F-JF7|LJL--777F-LFJ.
|
||||
FL7|LLJL77L7FJL7LJLJL--7F--7|F7LJLJL7|F--JLJLJL||L7|L7LJL-7F7-FJ|F7|FJF-J|L-7L7|F7||F7F-7F7LJ||F7F-7|L--JF-J||F7|FJ|LJ|LJF7||L7F---J77L--7.|
|
||||
J-|-J..LJ7JLJ|.L---7F-7LJF7L-JL7F---J||F7F7F7F7||FJ|F|F---J|L7L7||||L7L7FJ|LL7|||LJLJLJ-LJL-7|LJLJFJL--7FJJFJLJ|||L|F-JF7|||||||F7|F7-J7..7.
|
||||
.F|F|-|-|JJF----7F-J|FJF-JL7F-7|L----JLJLJLJLJ|||L7L-JL-7F7L7L7|||LJFJFJ|F7F7||||F7F-7F7F---JL----JF--7|L--JF-7LJL-JL--JLJLJL-JLJL-7J7LLF-L7
|
||||
FJ|-F.F.-7FL-7F7LJF7|L-JF-7LJL|||F---7F-------J|L-JF----J||||FJ|||F-JL|FJ|||||||LJ|L7LJ|L----------JF-JL7F7FJJ|F7F-7F7F7F---7F7F7F-J.-7-7|.J
|
||||
L-7||F-7LLF.FLJL-7|||F--JFJF7FJL-JF-7|L--7F---7L--7L7F---J|FJL7|||L-7FJ|FJ||||||F-JFJF-JF7F7F7F----7L--7LJLJF7|||L7|||||L--7LJLJ|L7J|||.|-7J
|
||||
...-JJ.|.FJ-F.F--J|LJ|F-7L-J|L-7F-JFJL7F7LJF7FJF--JFJ|F---JL-7|||L7FJL7||FJ|LJ||L-7L7|F7|||LJLJF7F7L7F7L---7|||||FJLJ||L7F7L---7|FJF77LL|.7.
|
||||
F7FJJ7.FFLJ7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|7F|-|7|.L7J.F|-|LF|...
|
||||
F-|||.J-F-F--.|JL|L|FJJ7|.|.J.L7.FJ-7||JF|J-LLFLJ|.|.LLL77.F7F|7LLFJ--LLJLJ7|FL.7J|.|-7.L7FJFFLL7LF|-7L--.-|.L-L--7-L7--J7L-JF-L--J|L7L-|-|7
|
||||
J-JJ77.FLJ.77|LF7|.|J7.L7.|7L7.F.FL7FFLFJ7LF7.FJL-.|J-J-L-FJ|LLJ||J.7||L|JJ.FJJFJ7L7||.-J|7-FJJL|FL.LJL|-L-|F|J|J.L7FJ.|7F-.|F7L|.JJ.J7J.LL7
|
||||
|.L|L-JJ-F|.|.|LFJ-J-F-JFFL7|.-|F-7F-F-7-JF-|7JLFJ7LJJ..J.|JJ||.LJFJL-JJJFLF7J.FLF.7-J-J.L|F7|.-.F|J7LF|.|||FF-|7||LL-7|LJJ.F|JF-7|-L-J.|.L-
|
||||
FL7F-|7J.|J-|LJ-J.LL7||-7J|F-|JF-|-F7|LJ.|L7L|7J|.FFJF-|-|||---JJ.7.L-L|.L--F-7FFJF|-|||7FFJLJ-|F.||7-|.F|F|J|.J7FL-.-J7L|.|7|F7-77|LJ.LF.L|
|
||||
-.LJ-L|--JL-FJJ.LFJL-J--JJFL-JL|LJ.L--J.F--JLL|.--JJ.7JLLFLJ...|-F.-.FJJFJJJL-L-J-L77LLL--J|..LLF.F-7.L-J.JJJL7LLLJ.JJJF-J7---LJ-L|7LL|-J7-|
|
16
2023/10/part1/cmd/main.go
Normal file
16
2023/10/part1/cmd/main.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"git.tristans.cloud/tristan/aoc/2023/10/part1/lib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin);
|
||||
pipeMap := part1.ReadMap(scanner)
|
||||
size := part1.LoopSize(pipeMap)
|
||||
println(size / 2)
|
||||
}
|
||||
|
89
2023/10/part1/lib/lib.go
Normal file
89
2023/10/part1/lib/lib.go
Normal file
|
@ -0,0 +1,89 @@
|
|||
|
||||
package part1
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Tiles = map[byte][2][2]int{
|
||||
'|': {{0,-1}, {0,1}},
|
||||
'-': {{-1,0}, {1,0}},
|
||||
'L': {{0,-1}, {1,0}},
|
||||
'J': {{0,-1}, {-1,0}},
|
||||
'7': {{0,1}, {-1,0}},
|
||||
'F': {{0,1}, {1,0}},
|
||||
}
|
||||
|
||||
func ReadMap(scanner *bufio.Scanner) (res []string) {
|
||||
for scanner.Scan() {
|
||||
res = append(res, scanner.Text())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func FindStart(pipeMap []string) (x,y int) {
|
||||
for y = range pipeMap {
|
||||
if x = strings.IndexRune(pipeMap[y], 'S'); x > -1 {
|
||||
return
|
||||
}
|
||||
}
|
||||
return -1, -1
|
||||
}
|
||||
|
||||
func FindFirst(pipeMap []string, sx,sy int) (int, int, int) {
|
||||
for y := sy-1; y <= sy+1;y++ {
|
||||
if y < 0 || y >= len(pipeMap) {
|
||||
continue
|
||||
}
|
||||
for x := sx-1; x <= sx+1 ;x++ {
|
||||
if x < 0 || x >= len(pipeMap[y]) {
|
||||
continue
|
||||
}
|
||||
side, ok := GetSide(pipeMap, sx,sy, x,y)
|
||||
if ok {
|
||||
return side,x,y
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1, -1, -1
|
||||
}
|
||||
|
||||
func GetSide(pipeMap []string, px,py, x,y int) ( int, bool ) {
|
||||
tile := pipeMap[y][x]
|
||||
dirs, ok := Tiles[tile]
|
||||
if !ok {
|
||||
return -1, false
|
||||
}
|
||||
for i,dir := range dirs {
|
||||
if x + dir[0] == px && y + dir[1] == py {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
return -1, false
|
||||
}
|
||||
|
||||
|
||||
func FindNext(pipeMap []string, side, x,y int) (int,int,int) {
|
||||
tile := pipeMap[y][x]
|
||||
|
||||
dir := Tiles[tile][1-side]
|
||||
|
||||
nx,ny := x+dir[0], y+dir[1]
|
||||
|
||||
nside, _ := GetSide(pipeMap, x,y, nx,ny)
|
||||
return nside,nx,ny
|
||||
}
|
||||
|
||||
func LoopSize(pipeMap []string) int {
|
||||
x,y := FindStart(pipeMap)
|
||||
side,x,y := FindFirst(pipeMap, x,y)
|
||||
count := 1
|
||||
for pipeMap[y][x] != 'S' {
|
||||
count++
|
||||
side,x,y = FindNext(pipeMap, side, x,y)
|
||||
}
|
||||
return count
|
||||
|
||||
}
|
||||
|
131
2023/10/part1/lib/lib_test.go
Normal file
131
2023/10/part1/lib/lib_test.go
Normal file
|
@ -0,0 +1,131 @@
|
|||
|
||||
package part1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"reflect"
|
||||
"bufio"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const basicInput =
|
||||
".....\n" +
|
||||
".S-7.\n" +
|
||||
".|.|.\n" +
|
||||
".L-J.\n" +
|
||||
".....\n"
|
||||
|
||||
var basicMap = []string{
|
||||
".....",
|
||||
".S-7.",
|
||||
".|.|.",
|
||||
".L-J.",
|
||||
".....",
|
||||
}
|
||||
|
||||
const complexInput =
|
||||
"7-F7-\n" +
|
||||
".FJ|7\n" +
|
||||
"SJLL7\n" +
|
||||
"|F--J\n" +
|
||||
"LJ.LJ\n"
|
||||
|
||||
var complexMap = []string{
|
||||
"7-F7-",
|
||||
".FJ|7",
|
||||
"SJLL7",
|
||||
"|F--J",
|
||||
"LJ.LJ",
|
||||
}
|
||||
|
||||
func TestReadMap(t *testing.T) {
|
||||
reader := bufio.NewScanner(strings.NewReader(basicInput));
|
||||
pipes := ReadMap(reader)
|
||||
equal(t, pipes, basicMap)
|
||||
}
|
||||
|
||||
func TestReadMapComplex(t *testing.T) {
|
||||
reader := bufio.NewScanner(strings.NewReader(complexInput));
|
||||
pipes := ReadMap(reader)
|
||||
equal(t, pipes, complexMap)
|
||||
}
|
||||
|
||||
func TestFindStart(t *testing.T) {
|
||||
x,y := FindStart(basicMap)
|
||||
equal(t, x, 1)
|
||||
equal(t, y, 1)
|
||||
}
|
||||
|
||||
func TestFindStartComplex(t *testing.T) {
|
||||
x,y := FindStart(complexMap)
|
||||
equal(t, x, 0)
|
||||
equal(t, y, 2)
|
||||
}
|
||||
|
||||
func TestFindFirstBasic(t *testing.T) {
|
||||
x,y := 1,1
|
||||
side,newX,newY := FindFirst(basicMap, x,y)
|
||||
equal(t, side, 0)
|
||||
equal(t, newX, 2)
|
||||
equal(t, newY, 1)
|
||||
}
|
||||
|
||||
func TestFindFirstComplex(t *testing.T) {
|
||||
x,y := 0, 2
|
||||
side,newX,newY := FindFirst(complexMap, x,y)
|
||||
equal(t, side, 1)
|
||||
equal(t, newX, 1)
|
||||
equal(t, newY, 2)
|
||||
}
|
||||
|
||||
func TestGetSide(t *testing.T) {
|
||||
side,ok := GetSide(basicMap, 1,1, 2,1)
|
||||
equal(t, side, 0)
|
||||
equal(t, ok, true)
|
||||
}
|
||||
|
||||
func TestFindNext(t *testing.T) {
|
||||
cx,cy := 2,1
|
||||
|
||||
s,nx,ny := FindNext(basicMap, 0, cx,cy)
|
||||
equal(t, nx, 3)
|
||||
equal(t, ny, 1)
|
||||
|
||||
s,nx,ny = FindNext(basicMap, s, nx,ny)
|
||||
equal(t, nx, 3)
|
||||
equal(t, ny, 2)
|
||||
|
||||
s,nx,ny = FindNext(basicMap, s, nx,ny)
|
||||
equal(t, nx, 3)
|
||||
equal(t, ny, 3)
|
||||
|
||||
s,nx,ny = FindNext(basicMap, s, nx,ny)
|
||||
equal(t, nx, 2)
|
||||
equal(t, ny, 3)
|
||||
|
||||
s,nx,ny = FindNext(basicMap, s, nx,ny)
|
||||
equal(t, nx, 1)
|
||||
equal(t, ny, 3)
|
||||
|
||||
s,nx,ny = FindNext(basicMap, s, nx,ny)
|
||||
equal(t, nx, 1)
|
||||
equal(t, ny, 2)
|
||||
|
||||
s,nx,ny = FindNext(basicMap, s, nx,ny)
|
||||
equal(t, nx, 1)
|
||||
equal(t, ny, 1)
|
||||
}
|
||||
|
||||
func TestLoopSize(t *testing.T) {
|
||||
size := LoopSize(basicMap)
|
||||
equal(t, size, 8)
|
||||
size = LoopSize(complexMap)
|
||||
equal(t, size, 16)
|
||||
}
|
||||
|
||||
func equal(t *testing.T, actual any, target any) {
|
||||
if !reflect.DeepEqual(actual, target) {
|
||||
t.Errorf("expected %v, got %v", target, actual)
|
||||
}
|
||||
}
|
||||
|
18
2023/10/part2/cmd/main.go
Normal file
18
2023/10/part2/cmd/main.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.tristans.cloud/tristan/aoc/2023/10/part1/lib"
|
||||
"git.tristans.cloud/tristan/aoc/2023/10/part2/lib"
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main () {
|
||||
scanner := bufio.NewScanner(os.Stdin);
|
||||
|
||||
pipeMap := part1.ReadMap(scanner)
|
||||
inside := part2.GetVolume(pipeMap)
|
||||
println(inside)
|
||||
}
|
||||
|
84
2023/10/part2/lib/lib.go
Normal file
84
2023/10/part2/lib/lib.go
Normal file
|
@ -0,0 +1,84 @@
|
|||
|
||||
package part2
|
||||
|
||||
import (
|
||||
"git.tristans.cloud/tristan/aoc/2023/10/part1/lib"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Loop map[[2]int]bool
|
||||
|
||||
func GetLoop(pipeMap []string) ( loop Loop ) {
|
||||
x,y := part1.FindStart(pipeMap)
|
||||
loop = Loop{{x,y}: true}
|
||||
side,x,y := part1.FindFirst(pipeMap, x,y)
|
||||
for pipeMap[y][x] != 'S' {
|
||||
loop[[2]int{x,y}] = true
|
||||
side,x,y = part1.FindNext(pipeMap, side, x,y)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetShapeOfS(pipeMap []string) () {
|
||||
return
|
||||
}
|
||||
|
||||
const CLEAR = "\u001b[0;0m";
|
||||
const OUT_OF_LOOP = CLEAR;
|
||||
const ON_LOOP = "\u001b[0;31m";
|
||||
const IN_LOOP = "\u001b[0;33m";
|
||||
|
||||
func GetVolume(pipeMap []string) int {
|
||||
loop := GetLoop(pipeMap)
|
||||
count := 0
|
||||
for y,line := range pipeMap {
|
||||
inLoop := false
|
||||
onDownEdge := false
|
||||
onUpEdge := false
|
||||
for x,c := range line {
|
||||
_,onLoop := loop[[2]int{x,y}]
|
||||
|
||||
if onLoop {
|
||||
switch c {
|
||||
case '|':
|
||||
inLoop = !inLoop
|
||||
case 'L':
|
||||
onDownEdge = true
|
||||
case 'F':
|
||||
onUpEdge = true
|
||||
case '7':
|
||||
if onDownEdge {
|
||||
onDownEdge = false
|
||||
inLoop = !inLoop
|
||||
} else if onUpEdge {
|
||||
onUpEdge = false
|
||||
}
|
||||
case 'J':
|
||||
if onUpEdge {
|
||||
onUpEdge = false
|
||||
inLoop = !inLoop
|
||||
} else if onDownEdge {
|
||||
onDownEdge = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
color := OUT_OF_LOOP
|
||||
if onLoop {
|
||||
color = ON_LOOP
|
||||
}
|
||||
if inLoop && !onLoop {
|
||||
count++
|
||||
color = IN_LOOP
|
||||
}
|
||||
if c == 'S' {
|
||||
color = "\u001b[41;30m"
|
||||
}
|
||||
fmt.Printf("%v%c", color, c)
|
||||
}
|
||||
println(CLEAR)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
88
2023/10/part2/lib/lib_test.go
Normal file
88
2023/10/part2/lib/lib_test.go
Normal file
|
@ -0,0 +1,88 @@
|
|||
|
||||
package part2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var inputMap = []string{
|
||||
"...........",
|
||||
".S-------7.",
|
||||
".|F-----7|.",
|
||||
".||.....||.",
|
||||
".||.....||.",
|
||||
".|L-7.F-J|.",
|
||||
".|..|.|..|.",
|
||||
".L--J.L--J.",
|
||||
"...........",
|
||||
}
|
||||
|
||||
var complexMap = []string{
|
||||
"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",
|
||||
}
|
||||
|
||||
var anotherMap = []string{
|
||||
".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...",
|
||||
}
|
||||
|
||||
var basicMap = []string{
|
||||
".....",
|
||||
".S-7.",
|
||||
".|.|.",
|
||||
".L-J.",
|
||||
".....",
|
||||
}
|
||||
|
||||
func TestGetLoop(t *testing.T) {
|
||||
loop := GetLoop(basicMap)
|
||||
equal(t, loop, Loop{
|
||||
{1,1}:true,
|
||||
{2,1}:true,
|
||||
{3,1}:true,
|
||||
{3,2}:true,
|
||||
{3,3}:true,
|
||||
{2,3}:true,
|
||||
{1,3}:true,
|
||||
{1,2}:true,
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetVolume(t *testing.T) {
|
||||
v := GetVolume(inputMap)
|
||||
equal(t, v, 4)
|
||||
}
|
||||
|
||||
func TestGetVolumeComplex(t *testing.T) {
|
||||
v := GetVolume(complexMap)
|
||||
equal(t, v, 10)
|
||||
}
|
||||
|
||||
func TestGetVolumeAgain(t *testing.T) {
|
||||
v := GetVolume(anotherMap)
|
||||
equal(t, v, 8)
|
||||
}
|
||||
|
||||
func equal(t *testing.T, actual any, target any) {
|
||||
if !reflect.DeepEqual(actual, target) {
|
||||
t.Errorf("expected %v, got %v", target, actual)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue