day 10 done
This commit is contained in:
+140
-1
@@ -1 +1,140 @@
|
||||
Paste any inputs into this file.
|
||||
|-L.FL-FJFL.|7FJ7F|F7-7F77.FL7---.7FF77--.|-F|FF--7FF7F-7F--77FFFJFJF7.F-LF7LFJJ.F|.|77F7F---7FLL.|FFJ.FF7-77..F77.-F-7FL-FF|77F-FFLL-FJ-|.J
|
||||
|7JF77-|L7J-F-JJL7|-|LJLF-|7.|.LLLJ7|-7.LFJFF--JF7L7|||FJ|F-J77L|F7.L-FJF----L7.FF.FJ-J-L-7|L|LJ7FJJJ.F|L-7L7.FF-|-7F-|J..||LJ-|-J-.|L|J|LF|
|
||||
LJ-LL|F7|LL7LLL-|-F7||..||..FJ.FJJF-7JJ|.7JLL--7|L7LJLJ|FJL-77|..FFJ7FJ7L7-|-JL.F--7LJJ|LJJ.F-|L7.FF-L7-F-7F77|J7||FLFJ|FFLL7.|JFJJ--J|.7-7|
|
||||
|.FJ.|F7-7L77|||L7JL-7LF777-JJ.|7F-L7JFJ7|F-|.LLJ|L---7||F--J7JFLF|JF-.--7||J.|F-.7LLLFF7||7F777L7FJ-||LJ7|||F|L-7.JJ.||7||J7.|-LL.7J.F7L7--
|
||||
F-7LF||.FLJL-7|FF|L7FL-L||F-7|FL7LJ|L7L|.LLJ|FJJLF---7|||L---7L7|L|7||FLFLJ|-FF-7|777FJ7|-FFJ|L77LL-F.JJJL7LLJ.|L7FJFF-77LF-7-|-|77L|7.L--7|
|
||||
F-JF-L7--J|JLL7-|LJ|F|J7L|J.J-|F7J7F|JF-7.|LF7F77L--7||LJF---JL-JJ|LJ7FJL7L|JLFJF|7FF7.-JJFL7|-F77J-777JF|L7J.|--L|J7|7LJ7JFJJ..|-J--7.L7.FJ
|
||||
L7J|7||J--L-F7.||LFL-JF7.F7.|.FL7.FF7L|7F|FF-7F-7F7FJLJF7L----7JFFJJ.J|7L|7L7JLL|JFFJ7.|.|F-J|FJL7|F7-|F7JF|FF.|.||7L-J7LF-||.L7J7L7FJ7.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7FJ|FJ|||F---J|L-7F-J||F----JL--7L7|LJ|F7L7L7||L--7L--7L--7L--7|||F-JFJLJLJF7F7F-JL--J|F7L-JFJJ-LJL-J.|F--
|
||||
-J||-LJJF-F-J7L-LJLJ|L---JL--J|||FJ|FJ|FJ||L-7F-JF7|L-7LJL-7F-7F7L|FJL7FJ|L7L7|||F7FJF--JF7.|F--J|||L-7L--7F-JLJ|L------J|L---J7|-J7FFL77||J
|
||||
LL||7.|LJ.|L-7L7-F-7|F7F-7F7F7|LJL7LJFJL7||F-JL--J||F7|F-7FJ|FJ|L-JL7FJL-JFJF||||||L7|F-7||FJL7F7|LJF-JFF-J|F--7L-7F-7F--J7F7|F7777LFL.LF-77
|
||||
.LL-F-77J.J7-|-F7|FJLJLJ-LJLJLJ-F7L-7|F7|LJ|F7F7F-J|||LJFJL7|L7L---7LJF---JF7|||LJ|FJLJFJ||L7FJ||L-7L--7L-7LJF7L-7||FJL----JL-JL77FF|-|-7|LL
|
||||
F7.F|-|--7JFF77|||L7F---7|F7FFF7|L--J|||L-7LJLJ||F7LJ|F7L7FJL7|F7F-JF7|F--7||||L-7LJF--JFJ|FJL7||F7L7F-JF7|F-JL-7|||L7F--------7L7----|FJ-7L
|
||||
L|-L--|FFFF7||FJ|L7|L--7|FJL7FJ|L---7|||F7|F---JLJL7FJ||7||F7||||L7FJLJ|F-J||||F7L-7|F77L7|L7FJ||||L||F7|||L---7LJLJFJL-------7|FJ-77JF77.7J
|
||||
F--||.F--7||||L7|J|L---JLJF7|L7|7F--JLJ|||||F-7F7F-JL7|L7|||||||L7||F7FJ|F7|||||L7FJ||L7FJL7||FJ||L7|||LJLJF7F7L--7-L-7F7F----J||--J-7LLJ-JJ
|
||||
LJFJ|FL-7LJLJL-JL7L----7F7|||FJL7L---7F||LJ||FJ||L7F-J|FJ|LJ||LJ-||LJ|L7LJ||||||FJL7||FJ|-FJ|||FJL7||||F---JLJL--7L--7|||L-7..LLJ7|.|F7FJ7L7
|
||||
|.L7L-|-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JL7L7F-JJF-----JF---JL--7F77|FJ||FJF7L-7--J||J
|
||||
FLLJ-LF7J||F-7F7L---7F7F-JF7||L7L-7LJF7|||||7LJF7LJFJL-7|FJFJL7LJLJFJL7||FJ|F---JL---JL-7F-JF-7FJFJ|FF7L-----7|F------J||FJL7|LJFJ|F7|F|FFL7
|
||||
JL---77J|--L7LJL-7F-J|LJF-JLJ|7|F7L--JLJ|LJL---JL-7|F7FJ|L7|F7L--7FJF7|||L7||F7F7F7F-7F7||F-JFJL7L-JFJL------J|L---7F--J|L7FJ|F-JLLJ||7LFJFJ
|
||||
.|L7||JF--JL|F7F7||F7|F-JF7F7L-J||F7F7JFJF7F7F7F--J|||L7L7||||F-7|L7|||||FJ|||||LJ|L7||||LJ-FJF7|F7FJF----7F7.|F---J|F--JF|L-JL-7L|-LJ--77FL
|
||||
L7LLJ.LJ.|FLLJ||||LJ||L--JLJL7F-JLJLJL-JFJLJ|||L--7|||FJ7||||||FLJF||||LJL7||||L-7|FJ||||F--JFJLJ|LJFJF---J|L7||F7F7||F7|FJF---7L7-7L|-L-7J|
|
||||
.J7.LL7F--J-||LJ|L-7||F-7F7F7LJF----7F--JF7.LJL7F-J|||L-7|||||L7F--J|LJ-F-J|||L7FJ|||LJ||L7F7L7FSL--J.L--7.L7||LJLJLJLJL7L7L--7|FJF-F|7|LL-7
|
||||
F||JJFFFJ|FFFF-7L7FJLJL7|||||F7L---7||F7F|L---7||F7|||F7||||||FJL7F7L--7|F7|||FJ|FJL--7|L7LJL7||L----7F--JF7|||F--------JFJF--JLJ7L7F777|.|L
|
||||
FL77.F777FF7JL7L-JL7LF7|LJ||LJL----JLJ||FJF7F7||LJ|LJ||LJ||||||F-J|L7F7|LJ|||||FJ|F7F-JL-JF77LJL---7FJL---JLJLJL----7.F7-|FJF--7F7L7J|JL-.L|
|
||||
|.L-77JL7F7F7.L--7FJFJ|L-7|L----------JLJFJ|||||F-JF7||F7LJLJLJ|F7|FJ||L-7||||||FJ|||F-7LFJ|F-7F7F-J|F7F--------7F--JFJL7|L-JF7LJL--77--J7L-
|
||||
L7FL7J|L7|LJL----JL-JFJF-J|F-7|F7F--7F7F-JFLJLJLJF-J||LJL7|F--7LJLJL7||F-JLJ||LJL-JLJ|FJFJFJ|FJ||L-7LJ|L-----7F7LJF-7|F-J|F--JL7F---J..F|LF|
|
||||
|.|LJL|-FL----------7|-L-7|L7L7||L-7|||L7F-----7LL7FJL7F7L7|F-J-F---J||L-7F-JL7FF7F-7|L7L7L-JL7||F7L-7|F----7LJ|F7L7||L--JL---7LJ7|7-J-7|-7|
|
||||
|.LF7FJF7F7-F7F-----JL-7FJ|7L7LJL--JLJL7LJF----JF-J|F7LJL7LJL-7FL----J|F-JL7F7|FJ||FJL7|FJF7F7LJLJ|F7||L---7|F7LJL7|||F--7F7F7L--7F77.LLJLJ7
|
||||
L7LJ7J|LFJL7||L-------7|L7|F7L--------7L7FJF---7L-7LJL--7L-7F7|F------JL-7FJ|||L7LJL--JLJFJLJL--7FJ|||L----J|||F-7LJLJL-7||||L7F7LJL-7-LJ||J
|
||||
F|7LF-7FJF7LJL--------JL-JLJL---7F7F--J7LJ.L7F-JF-JF7F--JF7LJ|||F7F-7F7F7||FJ||7L----7F-7L7F--7FJL-J|L7F---7||LJFJF-----JLJ|L7LJ|F7F-J7F-|J|
|
||||
77-7L7LJFJL7F7F7F7F7F---7F-7F7F7LJLJF7F7FF7-|L-7|F-JLJLF-JL-7LJ||LJFJ||||||L7||F-----JL7L-JL-7LJF--7L-J|F--JLJF7L7L---7-F7FJFJLFJ||L-7F|F7LL
|
||||
||LJ.L7FJF-J|LJLJ||LJ-F-J|FJ|LJL-7F7|||L-JL7|F-J|L----7L-7F-JLLLJF-JFJ|||||FJ|||F----7FJF----JF7L-7L7F7|L-----JL7|F7F7L7||L-JF7|FJL--JFF777|
|
||||
F-.J7LLJF|F-JF77FJ|F--JF7|L-J.F--J|LJLJF7F7LJL--JF----JF7|L7F7|JL|F7|F||LJ|||LJLJF---JL7L7F-7FJ|F-J7LJLJF------7|LJLJL7|||F77||LJLF7|F7|L77|
|
||||
F-|LJ7.|F||F-JL-JFJL7F-JLJF7F7L7F-JF-7FJ|||F7F7F7|F-7F7|||FJ||77LLJLJFJL7.||F----JF7F7FJL|L7LJFJL-7F---7L-----7LJF---7LJ|LJL-JL---J|FJLJFJF7
|
||||
.FL77F|LFLJL--7F7|F7||F---JLJL7LJF-J-LJFJ|LJ||LJLJL7||||LJ|FJL7-|.|L-L-7|-LJL--7F7||||L7FJFJF-JF7FJL7F7L------JF7|F--JF7|F------7F-J|F-7L-J|
|
||||
FL7|L77FJ|FF-7|||||LJ|L7F7F-7FJF7L----7L7L-7LJF7FF7|LJLJF-JL7FJ-F--7|L.LJ-||F--J|||LJ|FJL7L7|F-JLJF7LJ|F-------JLJL---J||L7F---7|L--J|LL7F7|
|
||||
FJ77.L-7JFLL7|LJ||L--J|LJLJFJL-JL-----JLL-7L7FJL7|||F7F7L7JFJL7.|FLFF-FJ|7.LL7F7|LJF7||F7L7||L7F--JL--J|F--7F7F--------J|FJ|F--JL7F-7L-7||LJ
|
||||
|LFL-7.-JFJFJL-7LJF-7-F7F7LL--7F7F-7F7F7F7L-J|F-J||||LJL7L-JF-JF77-|J7J-J7-|.||LJF7||LJ|L7LJL-JL-------JL-7|||L---------JL-JL-7LF||||F-J||JJ
|
||||
-.F|-L.L-F-JF-7|FFJFJFJLJL-7F-J|||JLJ||||L--7|L--JLJL--7L---JF-J|-7|J||7LJ7LLLJJF|LJL7-|FJF--7F7F7F-------J||L7F-7F-----7F7F7FJF7LJ-||JLLJ..
|
||||
LF-|JL|JLL-7|FJL-JFJFJF-7F7|L7FJ||F--J|||F--J|F-7F7F7F7L-----JF-J-|J-|FFJ|-JFLF|-L-7FJFJ|FJF7LJLJ|L---7F-7FLJ|LJFJ|F-7F7LJLJ|L-JL7J|LJ77.|F7
|
||||
FL.|..L-JF7LJL---7L-JFJFLJ||FJ|LLJL---JLJL-7FJL7LJ|||||F-7F7F7L-7-|J7L--7FJFFFFJ7LFJL7L7|L-JL7F-7L7F7|LJLL----77L-JL7LJL7.F7L---7L--7-LF-7.7
|
||||
|FJ77F-J-||F----7L--7L7F--J|L-JF------7F---J|F-JF7LJLJ|L7|||||F7|J|F|F-7|J|F-J|F7FJF-JFJL7F7FJ||L7LJL---------JF7.F7|F-7L-JL---7L7F-J7-|-F7|
|
||||
L||L--JF-JLJF7F7L--7L-JL--7L--7L-----7||-F7FJL7FJL--7FL7|||LJ||LJ.|-F-J|.F7JF7F||L7|F7L7FJ||L-JF7L-------------J|FJ||L7L--7F--7L7LJ||.||L7-J
|
||||
.JJJ.J||F7F-JLJL7F7L7F7|F7L-7FJF-----J|L-JLJF-JL7F-7L-7||LJ7FLJJF77L-7||F-JLF7FJL-JLJ|FJ|FJL-7FJL----7F---------JL7||FJ.F7LJF7L7L---77F--|-L
|
||||
FL|.FJFLJ||F----J|L7LJ|FJL--J|-L-7F7F7L7F7F7L---JL7L7FJ|L7F--7JFJL-7||-|L|.|||L-----7LJFJL--7|L-----7|L----7F7F7F7|LJL-7|L7FJL7|F---J-JJFF-L
|
||||
-.FJ|.F|7LJL-----J|L-7|L----7|F7JLJLJL7|||||F7F7F7L7||FL7LJF-J7F|-LL77.J.77FJL------JF7L-7FFJL7F----JL--7F7LJ||||LJF7F-J|FJ|F-JLJF7J.FJ-F|7|
|
||||
L-F-7-F|J7FF7F----77FJL-----JLJ|F-----JLJ||||LJ|||FJ|L-7|F7L7-L.|JJL|J-F7.LL--7F7F7F7||F7L7L7FJL----7F-7|||F7LJLJF-J|L--JL-JL---7||7F7J|FJFL
|
||||
LFJL|LJL|F-J|L--7FJFJF----7F--7LJF---7F77LJ|L-7||LJFL--JLJL-J.FJ.777L7FF7.L7.|LJ||LJLJLJL7L-JL7F7F77LJFJLJLJL7F-7L-7|F-7F7F-----J|L7-J.-J7F7
|
||||
7J.|JF|7-L-7|JF7|L-JFJF-7FJ|F-JF7|F-7LJL-7FJF7||L-----7F7-F--7JJ-F7J-FL-..LLF7JLLJJ-F7.F-JF7F7LJLJL--7L-----7LJ7L--J|L7|||L------JFJ7|||FFL|
|
||||
|7L.L||JLF-JL-JLJF7FJ7L7LJFJL7FJ||L7L----J|FJLJL7F----J|L-JF7|J.FF7-F7F||7L||L----7FJL7L--JLJL7F-7F-7L-----7L-7F7F7-L-JLJ|F7F-7F--JF7FF--JL|
|
||||
|7-|.L|..L---7F7FJ||F--JF7L7FJ|FJL7L---7F7LJF---JL--7F7|F--JLJF7FJ|7F7J7F7FFL----7|L7FJF7F7F77LJFJ|FJF----7L7FJ|LJL--7F--J|LJJLJF--JL7J.|.FJ
|
||||
FJ7L|J|FF--7FJ|LJ7LJL--7|L7|L-JL--JF7F7LJL7|L------7LJLJL-----J|L7L--7.-JL-F.LF--JL-JL7|LJLJL-7FL-JL7|F-7FJ|LJFJF----JL--7L---7FJF7F7|.FJ-|7
|
||||
L7|J|JL-L-7|L7|F-------JL7LJF----7-||||F-7L-7F7.F-7L7F7F7F7F7F-J-|F--J7|-J|JFLL-----7FJL-7F7F-JF7JF7LJL7|L----JFJFF77F-7FJF--7LJFJ||||F--|.|
|
||||
L|.FF7|LLFJL7LJL-7F------JF7L---7L-JLJLJF|F-J|L7|FJ7LJLJLJLJLJJFFJ|L|FF-7|F7JLF-7F--J|F-7LJ||F7|L7|L---JL---7F7|F7|L-JFJL7L-7|F7|7||||7LF-|7
|
||||
-L-FFFJ7FL-7|F--7LJF------J|F---JF----7F7LJF7|FJ||FF7F----7F--7-L7L7|7L7L-7LF|L7|L--7|L7L--JLJ||FJL--------7|||LJLJF7FJF-JF-J|||L7||LJL7|J|L
|
||||
JLLLJ|-F---J|L-7|F7L7F7F--7|L--7FJLF--J|||FJ||L-J|FJLJF---J|F-JF-JFJF7|L7FJF7F7|L---JL-JF-7F-7LJL7F--------J||L7F--JLJ-L-7L-7LJL-JLJJ|J.F7F7
|
||||
LL7LL||L---7L7FJLJL7||LJF-JL--7LJF-JF-7|L7|FJ|F--J|F--JF7F7|L-7L-7|-|L7||L7|LJLJF7F-7F-7|FJ|JL7F7|L----7F7F7LJJ|L-------7|F7L---7L|7L|-F-JLJ
|
||||
.F|7|.F-7F7L7|L--7FJLJF7L----7L7JL-7|FJ|FJ||FJL-7FJ|F--JLJLJF-JF7||FJFJFJFJ|F--7|LJLLJFJ|L-JF7LJ||7F7F7LJLJL--7L-------7|LJ|F-7FJ.L7-|L.FJJ7
|
||||
LJ|FF-L7LJL-JL-7FJL7F7||F7F-7L7L-7FJ||J|L-JLJF7FJL7LJF------JF7||||L7L7L7|-LJF7LJF----JFJF--JL--JL-JLJ|F-----7L-------7|L-7||L||-L-F77.FFJ.J
|
||||
||L77FFJF-----7LJF7LJLJLJ|L7||L-7|L-JL7|F--7FJLJF7|F7L-7F--7FJLJLJL7|FJL|L7F7|L-7L----7L7L-7F7F7F7F7F7LJF--7LL--------JL--JLJ-LJ.|.L--FJ.F||
|
||||
.F7FF7L-JJF7F-JF-JL-7F--7|FJL---JL---7LJL-7|L---JLJ|L7FJL7FJL7F---7|||7-|FJ||L7FJF7F--JFJF7LJLJLJLJLJL--JF-JF7F----------7F7F7J.F77FL-L|.F7-
|
||||
F|FFJL7F7F||L-7|FF7|LJF-J|L7F---7F--7|F-7FJL--7F7F-JF||F7|L-7LJF--JLJL7FJ|FJ|FJ|-||L7F-JFJL7F7F-7F7F-----JF7|||F--------7LJLJL-7-7-|F--F7JL|
|
||||
-FLL-7LJL-JL--J|FJ|F7JL-7L-J|F--J|F-JLJFJL---7|||L--7|||||F-JF7L----7FJL7|L7|L7|FJL7||F7L-7LJ||FJ||L------JLJLJL7JF----7L------J.|J|F-FLJ..F
|
||||
LLLF-JF-7F7F-7FJL7LJL---JF7FJ|F7FJL7-F7L---7FJLJ|F--JLJ||||F7||JF7F7||J.||FJ|FJLJF7|LJ||F-JF7LJL-J||F7F7F--7F7F7L7|F---J7F7F----7JJLF77-77.|
|
||||
|LFL-7L7||||FJL7LL7F-7F7FJ|L7LJ||F-JFJL---7||F-7LJF7F7FJLJLJLJ|FJLJLJL7FJ|L7|L7F-JLJ7FJ|L--JL7F-7FJFJLJ|L7FLJLJL-J||F7F--JLJF---J-LJ|L|---77
|
||||
J7|JLL7|||||L--JF7||FJ|||FJFJF-J|L--JF----JLJ|FJF7|LJ|L-7F----JL-----7|L7|FJL-JL7F7-FJFJ|F7F7||FJL7L-7FJFL-----7F7|||||F---7L7F7F7|FF777L-JF
|
||||
|F7J.F||LJLJF7F7|LJ|L7|LJL-JJL--JF---JF----7F|L-J|L7FJF-J|F7FF7F--7JFJ|FJ|L----7LJ|FJFJJFJ||LJ|L-7|JFJL--------J|LJLJ|||F-7L-J|LJL7FJ|7--JFJ
|
||||
L7J.-L||F---JLJLJF7L7LJFF---7F--7L-7F7L7F--JFJF7FJFJL7L-7||L7|||F-JFJFJ|FJ|F--7L-7LJFJF7|FJL7FJF-JL-JF7F----7F-7|F---J|||FJF7.L-7FJ|FJ..FFF7
|
||||
||.L|JLJL7F7F-7F7|L-JF7FJF-7LJF-JF-J||FJL7F-JFJ||FJF-JF-JLJFJ||||7FJFJFJ|F-JF-JF7L7FJFJ|||JLLJJL7F7F7|||F-7FJL7|||JF-7|LJL7|L7F7|L7|L77-FLL-
|
||||
|77||7|.LLJ||FJ|||F--JLJFJFJF7L--JF7|LJF-J|F-J.LJL7L7.L---7L7||||FJFJ|L7LJF-JF7|L-J|FJFJ|L7F7F--J|||LJLJL7LJ-FJ||L7L7||F--J|FJ||L7||FJF-7JJJ
|
||||
|J|-7-JFLLFJ|L7|||L----7|-L-JL----JLJF7L-7||LF77F7L7L7F7F7|FJ|||||FJF77L-7|F7||L7F-JL7|F|FJ||L--7|LJF-7F-J|F7|FJ|FJ7||||JF7|L7|L7|LJL-JFJJ||
|
||||
|.|LJL|7|.L7|FJ|LJF----J|F-------7F--J|F-J|L7|L7||FJFJ||||||FJ||||L7|L--7|||||L-J|LF-JL7|L7|L7F7LJF7L7LJF--JLJL-JL--JLJL-JLJFJL7||F---7||.F7
|
||||
7FJ7JFJ-LF7LJL-JF7L-----JL------7|L--7LJF-JFJ|FJ|||FJFJLJLJLJFJ|||FJL7F7||LJ|L--7L7L-7FJL7|L7||L7FJ|FJF-JF7F7F---7F-7F-7F7F7L--JLJL-7-LJ77L-
|
||||
FJF|-|J-J|--FLF-JL--7F----------JL---JF7L7FJF||FJLJL7|F--7F--JFJ|||F7LJ||L-7|F7J|FJF7|L-7||FJ||FJL7|L-JF-JLJLJJF7LJFLJL|||||F7F7F7F7L77|||7|
|
||||
F7F-7|F|FL-77JL----7|L-7F7F7F7F-----7FJL-JL7FJ|L--7FJLJF7|L7F7|FJ|||L7FJ|F7||||FJ|FJ||F-J||L7|||F7||F7FL---7LF7|L-----7||||LJLJ||||L7L77JLFJ
|
||||
|-J|-|F|7J.LL-.F7F7||F-J|LJLJLJF-7F-JL---7FJL7|F7FJ|F7FJ||FJ||||FJ||FJL7LJLJ||LJFJL7|||F-J|FJ|||||||||F7F--JFJLJF---7FJLJ|L---7||LJ||FJ|.7.|
|
||||
7FFJF-F--.|F-JF|LJLJLJF7|F-77F7|FJL7LF7F7||F7||||L7||||FJ||7|||||FJ||F7L---7||F-J.L||||L-7||FJ||||||||||L-7J|F-7L--7||F7.|F7F7|LJJF7LJF-..F7
|
||||
-FJFJF|JJ7L|JL|L---7F7|LJL7L-JLJL--JFJ||||||||LJ|FJ||LJ|FJL7||||||FJ|||F-7FJ||L7F7FJ||L7FJ||L7||||||||||F7L-JL7|F7FJ|LJL7|||||L---JL--7|FLF-
|
||||
L|-|F7.L7--7FF-F---J|||F--JF7F7F-7F-JFJ|LJ||||F-J|FJ|FFJL7FJ|LJ|||L7||||FJL7||FJ|||J||-||-LJFJ|LJ||||LJ|||F7F-J||LJLL-7FJ|||||F-7F7F--J--LJ|
|
||||
.|FJF-7-LLLLFJ.L---7|||L7F-JLJ||FJ|F-JFJF-J|LJL7FJL7L7L-7|L7L-7|||FJ|||||F7|LJL7|||FJL7||F7-|FJF-J|||F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7L------JL7L7|L7FJL7|L7F--7F7L7|||FJ|FJ|L-7FF-JFJFJ|F-JL7||F7|FJL--JLJ||||LJ|||L7LJLJ|F--JLJLJLJFJL-7|||F7L--JL-7LF7.L7
|
||||
.FF.J-JF-L-7--F.F.F7FJF-7F7F---J-LJFJ|F7LJFJ|F7||L7|||||FJL7|F7|FJF7L7|FJL7F7||||LJL------7|||||FJ|L7|7F--JL------7F7L7F-JLJ||L7F7F-7|7LL-J|
|
||||
.F|.L|.F7JFJJL7.LF|LJFJ|LJLJF----77L7LJL-7|FJ|||L7|||||||F7|||LJ|FJ|FJLJF-J|||LJL7F7F7F7F7|LJ||FJFJFJL7|F--7F7F---J||L|L---7LJJLJLJLLJJJ.|JF
|
||||
FLJJFFFF77J-J7|..FJF7|F--7F-JF--7L7F|F7F-JLJFJLJFJ|||||||||||L-7||FJL--7L--J||F--J|||LJ||LJF7LJL7||L7FJ||F-J|||LF7FJL7L7F--J7L7JJ7..LL7FF77J
|
||||
L-JJL7-7J--7JLJ.LL-JLJL-7|L--JF7L7L-J|||7F--JF7FJFJ||||||||||F-JLJL-7F-JF7F-J|L7F7||L-7LJ7FJ|F--J|F-JL7|||F7||L-J||F-JFJL-7JJ7|FFF7FFJ-7LJL.
|
||||
FL7-|J.L7LJJF-F--F------JL-7F-JL-JF-7||L7|F7FJLJFJFJ|||||||||L7-F7JFJL--J|L-7|F|||||F7L7F7|FJL7F7|L-7FJ||LJ|||F-7LJL-7L---JJLFJ7F|-JJ7LL7-|7
|
||||
77|.|L7LL7J--.L.-L----7F7F7LJF-7F-JFJ||FJLJ|L7F7L7L7||||LJLJ|FJFJL-JF7F-7|F-J|FJ|||||L7LJLJ|F-J||||FJL7LJF-J|||FJF7F7L----77FL7|JL77J|F|-FL7
|
||||
J-77J7L7LF-7L-LFJ|L|L|LJLJ|F7|FJL77L7||L7F-JFJ|L-JFJLJ|L---7|L7L-7F7|LJ.||L-7|L7|||LJFJF-7FJL--J||FJF7L7FJF7|||L7||||F7F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||LJ7|7.FFJ7JLL7F7JJ.F|J.FJ.JJ.7.LL7FJJL7LLJ-J77FJ-|FFLJJ7|.|FFL||--7|J.|.L77L-L|7FL7-|L7-77
|
||||
LJ-LJ.F-|.7|...||7F77|F|J-.|FLFL77-|J.|.|JLJJ|LLLJ|-F|77-||L|.F-FJJ.|-LJ7L7J.F--7LLLJ.FJJ.F|J-|||.F|FFJ|||7.|-J-LJ.L--7L--|FFJJ7.F7J|-JL-.F7
|
||||
7JFF.FF-L-LJJJ-7JL7LLL|7JJ.LJJLLLFJLFJ7JJL.LL--JJLJ..JLL-FF---J.J.F.L.J.|-|LFF--7-L|-LF.J-JJJLLF--L-|J.L|L|.J-J.LLJJ-L|.|-L-F---J.LJJJ.FJL|7
|
||||
@@ -1,6 +1,123 @@
|
||||
import os
|
||||
import numpy as np
|
||||
from queue import Queue
|
||||
|
||||
with open(r'advent_of_code\2023\day_10\input.txt', 'r') as file:
|
||||
input = file.read()
|
||||
|
||||
print(input)
|
||||
simple_test_input = '''.....
|
||||
.S-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....'''
|
||||
|
||||
complex_test_input = '''7-F7-
|
||||
.FJ|7
|
||||
SJLL7
|
||||
|F--J
|
||||
LJ.LJ'''
|
||||
|
||||
# print(simple_test_input)
|
||||
# print(complex_test_input)
|
||||
|
||||
#input = simple_test_input.split('\n')
|
||||
#input = complex_test_input.split('\n')
|
||||
input = input.split('\n')
|
||||
#print(input)
|
||||
|
||||
|
||||
NORTH = (-1, 0)
|
||||
SOUTH = (1, 0)
|
||||
WEST = (0, -1)
|
||||
EAST = (0, 1)
|
||||
|
||||
pipe_directions = {
|
||||
'|': (NORTH, SOUTH),
|
||||
'-': (WEST, EAST),
|
||||
'L': (NORTH, EAST),
|
||||
'J': (NORTH, WEST),
|
||||
'7': (WEST, SOUTH),
|
||||
'F': (SOUTH, EAST),
|
||||
'.': (),
|
||||
}
|
||||
|
||||
|
||||
def performLeeAlgorithm(pipe_map: list[list], distance_map: list[list], start_position: tuple[int]) -> None:
|
||||
# Initialize a queue and add the start position to it
|
||||
queue = Queue()
|
||||
queue.put(start_position)
|
||||
# Set the distance of the start position to 0
|
||||
distance_map[start_position[0]][start_position[1]] = 0
|
||||
|
||||
# Continue until the queue is empty
|
||||
while not queue.empty():
|
||||
# Get the next position from the queue
|
||||
current_row, current_col = queue.get()
|
||||
# Iterate over the directions that the pipe at the current position allows
|
||||
for delta_row, delta_col in pipe_directions[pipe_map[current_row][current_col]]:
|
||||
# Calculate the next position
|
||||
next_row, next_col = current_row + delta_row, current_col + delta_col
|
||||
# If the next position is a pipe and its distance has not been set yet
|
||||
if pipe_map[next_row][next_col] != '.' and distance_map[next_row][next_col] == -1:
|
||||
# Set the distance of the next position
|
||||
distance_map[next_row][next_col] = distance_map[current_row][current_col] + 1
|
||||
# Add the next position to the queue
|
||||
queue.put((next_row, next_col))
|
||||
|
||||
|
||||
|
||||
# Convert each row in the input to a list and store them in a list
|
||||
pipe_map = [list(row) for row in input]
|
||||
|
||||
# Pad the pipe_map with '.' on all sides
|
||||
pipe_map = np.pad(pipe_map, 1, constant_values='.')
|
||||
|
||||
# Create a distance_map with the same shape as pipe_map, filled with -1
|
||||
distance_map = np.full_like(pipe_map, -1, dtype=np.int32)
|
||||
|
||||
# Convert pipe_map and distance_map to lists
|
||||
pipe_map = pipe_map.tolist()
|
||||
distance_map = distance_map.tolist()
|
||||
|
||||
# find start location
|
||||
START = None
|
||||
for i, row in enumerate(pipe_map):
|
||||
for j, x in enumerate(row):
|
||||
if x == 'S':
|
||||
START = (i, j)
|
||||
break
|
||||
if START:
|
||||
break
|
||||
|
||||
# Initialize the directions for the start ('S') pipe as an empty list
|
||||
pipe_directions['S'] = []
|
||||
|
||||
# Define the start position
|
||||
start_row, start_col = START
|
||||
|
||||
# Check the pipe in each direction from the start position
|
||||
# If the pipe in that direction allows movement towards the start position, add the opposite direction to pipe_directions['S']
|
||||
|
||||
# Check the pipe to the north
|
||||
north_pipe = pipe_map[start_row + NORTH[0]][start_col + NORTH[1]]
|
||||
if SOUTH in pipe_directions[north_pipe]:
|
||||
pipe_directions['S'].append(NORTH)
|
||||
|
||||
# Check the pipe to the south
|
||||
south_pipe = pipe_map[start_row + SOUTH[0]][start_col + SOUTH[1]]
|
||||
if NORTH in pipe_directions[south_pipe]:
|
||||
pipe_directions['S'].append(SOUTH)
|
||||
|
||||
# Check the pipe to the east
|
||||
east_pipe = pipe_map[start_row + EAST[0]][start_col + EAST[1]]
|
||||
if WEST in pipe_directions[east_pipe]:
|
||||
pipe_directions['S'].append(EAST)
|
||||
|
||||
# Check the pipe to the west
|
||||
west_pipe = pipe_map[start_row + WEST[0]][start_col + WEST[1]]
|
||||
if EAST in pipe_directions[west_pipe]:
|
||||
pipe_directions['S'].append(WEST)
|
||||
|
||||
performLeeAlgorithm(pipe_map, distance_map, START)
|
||||
|
||||
print(np.max(distance_map))
|
||||
|
||||
|
||||
@@ -1,6 +1,200 @@
|
||||
import os
|
||||
import numpy as np
|
||||
from queue import Queue
|
||||
|
||||
with open(r'advent_of_code\2023\day_10\input.txt', 'r') as file:
|
||||
input = file.read()
|
||||
|
||||
print(input)
|
||||
simple_test_input = '''.....
|
||||
.S-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....'''
|
||||
|
||||
complex_test_input = '''7-F7-
|
||||
.FJ|7
|
||||
SJLL7
|
||||
|F--J
|
||||
LJ.LJ'''
|
||||
|
||||
last_test_input = '''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'''
|
||||
|
||||
# print(simple_test_input)
|
||||
# print(complex_test_input)
|
||||
|
||||
#input = simple_test_input.split('\n')
|
||||
#input = complex_test_input.split('\n')
|
||||
#input = last_test_input.split('\n')
|
||||
input = input.split('\n')
|
||||
#print(input)
|
||||
|
||||
|
||||
NORTH = (-1, 0)
|
||||
SOUTH = (1, 0)
|
||||
WEST = (0, -1)
|
||||
EAST = (0, 1)
|
||||
|
||||
pipe_directions = {
|
||||
'|': (NORTH, SOUTH),
|
||||
'-': (WEST, EAST),
|
||||
'L': (NORTH, EAST),
|
||||
'J': (NORTH, WEST),
|
||||
'7': (WEST, SOUTH),
|
||||
'F': (SOUTH, EAST),
|
||||
'.': (),
|
||||
}
|
||||
|
||||
|
||||
def performLeeAlgorithm(pipe_map: list[list], distance_map: list[list], start_position: tuple[int]) -> None:
|
||||
# Initialize a queue and add the start position to it
|
||||
queue = Queue()
|
||||
queue.put(start_position)
|
||||
# Set the distance of the start position to 0
|
||||
distance_map[start_position[0]][start_position[1]] = 0
|
||||
|
||||
# Continue until the queue is empty
|
||||
while not queue.empty():
|
||||
# Get the next position from the queue
|
||||
current_row, current_col = queue.get()
|
||||
# Iterate over the directions that the pipe at the current position allows
|
||||
for delta_row, delta_col in pipe_directions[pipe_map[current_row][current_col]]:
|
||||
# Calculate the next position
|
||||
next_row, next_col = current_row + delta_row, current_col + delta_col
|
||||
# If the next position is a pipe and its distance has not been set yet
|
||||
if pipe_map[next_row][next_col] != '.' and distance_map[next_row][next_col] == -1:
|
||||
# Set the distance of the next position
|
||||
distance_map[next_row][next_col] = distance_map[current_row][current_col] + 1
|
||||
# Add the next position to the queue
|
||||
queue.put((next_row, next_col))
|
||||
|
||||
|
||||
def fill_seq(distance_map: list[list]) -> None:
|
||||
# Initialize a queue with the starting position (0, 0)
|
||||
positions_queue = Queue()
|
||||
start_row, start_col = 0, 0
|
||||
positions_queue.put((start_row, start_col))
|
||||
distance_map[start_row][start_col] = -2
|
||||
|
||||
# Define the possible movements in the grid (right, left, down, up)
|
||||
row_directions = [0, 0, 1, -1]
|
||||
col_directions = [1, -1, 0, 0]
|
||||
|
||||
# While there are positions in the queue
|
||||
while not positions_queue.empty():
|
||||
# Get the next position from the queue
|
||||
current_row, current_col = positions_queue.get()
|
||||
|
||||
# Try moving in each direction from the current position
|
||||
for direction in range(4):
|
||||
next_row = current_row + row_directions[direction]
|
||||
next_col = current_col + col_directions[direction]
|
||||
|
||||
# If the next position is inside the grid and its distance is -1
|
||||
if (0 <= next_row < len(distance_map) and 0 <= next_col < len(distance_map[0])
|
||||
and distance_map[next_row][next_col] == -1):
|
||||
# Set the distance at the next position to -2
|
||||
distance_map[next_row][next_col] = -2
|
||||
# Add the next position to the queue
|
||||
positions_queue.put((next_row, next_col))
|
||||
|
||||
|
||||
def insert_between(input_array: np.array, fill_value) -> np.array:
|
||||
# Calculate the shape of the output array, which is twice the shape of the input array minus 1
|
||||
output_shape = 2 * np.array(input_array.shape) - 1
|
||||
# Create an output array filled with the fill value and with the calculated shape
|
||||
output_array = np.full(output_shape, dtype=input_array.dtype, fill_value=fill_value)
|
||||
# Copy the values from the input array to the output array, skipping every other row and column
|
||||
output_array[::2, ::2] = input_array
|
||||
return output_array
|
||||
|
||||
# Convert each row in the input to a list and store them in a list
|
||||
pipe_map = [list(row) for row in input]
|
||||
|
||||
# Pad the pipe_map with '.' on all sides
|
||||
pipe_map = np.pad(pipe_map, 1, constant_values='.')
|
||||
|
||||
# Create a distance_map with the same shape as pipe_map, filled with -1
|
||||
distance_map = np.full_like(pipe_map, -1, dtype=np.int32)
|
||||
|
||||
# Convert pipe_map and distance_map to lists
|
||||
pipe_map = pipe_map.tolist()
|
||||
distance_map = distance_map.tolist()
|
||||
|
||||
# find start location
|
||||
START = None
|
||||
for i, row in enumerate(pipe_map):
|
||||
for j, x in enumerate(row):
|
||||
if x == 'S':
|
||||
START = (i, j)
|
||||
break
|
||||
if START:
|
||||
break
|
||||
|
||||
# Initialize the directions for the start ('S') pipe as an empty list
|
||||
pipe_directions['S'] = []
|
||||
|
||||
# Define the start position
|
||||
start_row, start_col = START
|
||||
|
||||
# Check the pipe in each direction from the start position
|
||||
# If the pipe in that direction allows movement towards the start position, add the opposite direction to pipe_directions['S']
|
||||
|
||||
# Check the pipe to the north
|
||||
north_pipe = pipe_map[start_row + NORTH[0]][start_col + NORTH[1]]
|
||||
if SOUTH in pipe_directions[north_pipe]:
|
||||
pipe_directions['S'].append(NORTH)
|
||||
|
||||
# Check the pipe to the south
|
||||
south_pipe = pipe_map[start_row + SOUTH[0]][start_col + SOUTH[1]]
|
||||
if NORTH in pipe_directions[south_pipe]:
|
||||
pipe_directions['S'].append(SOUTH)
|
||||
|
||||
# Check the pipe to the east
|
||||
east_pipe = pipe_map[start_row + EAST[0]][start_col + EAST[1]]
|
||||
if WEST in pipe_directions[east_pipe]:
|
||||
pipe_directions['S'].append(EAST)
|
||||
|
||||
# Check the pipe to the west
|
||||
west_pipe = pipe_map[start_row + WEST[0]][start_col + WEST[1]]
|
||||
if EAST in pipe_directions[west_pipe]:
|
||||
pipe_directions['S'].append(WEST)
|
||||
|
||||
performLeeAlgorithm(pipe_map, distance_map, START)
|
||||
|
||||
for row_index in range(len(pipe_map)):
|
||||
for col_index in range(len(pipe_map[row_index])):
|
||||
if distance_map[row_index][col_index] == -1:
|
||||
pipe_map[row_index][col_index] = '.'
|
||||
|
||||
distance_map = insert_between(np.array(distance_map), -1).tolist()
|
||||
pipe_map = insert_between(np.array(pipe_map), '.').tolist()
|
||||
|
||||
|
||||
for row_index in range(len(pipe_map)):
|
||||
for col_index in range(1, len(pipe_map[row_index]), 2):
|
||||
if EAST in pipe_directions[pipe_map[row_index][col_index-1]] and WEST in pipe_directions[pipe_map[row_index][col_index+1]]:
|
||||
pipe_map[row_index][col_index] = '-'
|
||||
distance_map[row_index][col_index] = 0
|
||||
|
||||
for row_index in range(1, len(pipe_map), 2):
|
||||
for col_index in range(len(pipe_map[row_index])):
|
||||
if SOUTH in pipe_directions[pipe_map[row_index-1][col_index]] and NORTH in pipe_directions[pipe_map[row_index+1][col_index]]:
|
||||
pipe_map[row_index][col_index] = '|'
|
||||
distance_map[row_index][col_index] = 0
|
||||
|
||||
fill_seq(distance_map)
|
||||
|
||||
distance_map = np.array(distance_map)
|
||||
distance_map = np.delete(distance_map, list(range(1, distance_map.shape[0], 2)), axis=0)
|
||||
distance_map = np.delete(distance_map, list(range(1, distance_map.shape[1], 2)), axis=1)
|
||||
|
||||
unique, counts = np.unique(distance_map, return_counts=True)
|
||||
print(dict(zip(unique, counts))[-1])
|
||||
+173
-1
@@ -1 +1,173 @@
|
||||
# Day 10 Puzzle Text.
|
||||
|
||||
<article class="day-desc"><h2>--- Day 10: Pipe Maze ---</h2><p>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.</p>
|
||||
<p>You wander around for a while, but you don't find any people or animals. However, you do occasionally find signposts labeled "<a href="https://en.wikipedia.org/wiki/Hot_spring" target="_blank">Hot Springs</a>" 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.</p>
|
||||
<p>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.</p>
|
||||
<p>Scanning the area, you discover that the entire field you're standing on is <span title="Manufactured by Hamilton and Hilbert Pipe Company">densely packed with pipes</span>; 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).</p>
|
||||
<p>The pipes are arranged in a two-dimensional grid of <em>tiles</em>:</p>
|
||||
<ul>
|
||||
<li><code>|</code> is a <em>vertical pipe</em> connecting north and south.</li>
|
||||
<li><code>-</code> is a <em>horizontal pipe</em> connecting east and west.</li>
|
||||
<li><code>L</code> is a <em>90-degree bend</em> connecting north and east.</li>
|
||||
<li><code>J</code> is a <em>90-degree bend</em> connecting north and west.</li>
|
||||
<li><code>7</code> is a <em>90-degree bend</em> connecting south and west.</li>
|
||||
<li><code>F</code> is a <em>90-degree bend</em> connecting south and east.</li>
|
||||
<li><code>.</code> is <em>ground</em>; there is no pipe in this tile.</li>
|
||||
<li><code>S</code> is the <em>starting position</em> of the animal; there is a pipe on this tile, but your sketch doesn't show what shape the pipe has.</li>
|
||||
</ul>
|
||||
<p>Based on the acoustics of the animal's scurrying, you're confident the pipe that contains the animal is <em>one large, continuous loop</em>.</p>
|
||||
<p>For example, here is a square loop of pipe:</p>
|
||||
<pre><code>.....
|
||||
.F-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
</code></pre>
|
||||
<p>If the animal had entered this loop in the northwest corner, the sketch would instead look like this:</p>
|
||||
<pre><code>.....
|
||||
.<em>S</em>-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
</code></pre>
|
||||
<p>In the above diagram, the <code>S</code> tile is still a 90-degree <code>F</code> bend: you can tell because of how the adjacent pipes connect to it.</p>
|
||||
<p>Unfortunately, there are also many pipes that <em>aren't connected to the loop</em>! This sketch shows the same loop as above:</p>
|
||||
<pre><code>-L|F7
|
||||
7S-7|
|
||||
L|7||
|
||||
-L-J|
|
||||
L|-JF
|
||||
</code></pre>
|
||||
<p>In the above diagram, you can still figure out which pipes form the main loop: they're the ones connected to <code>S</code>, pipes those pipes connect to, pipes <em>those</em> pipes connect to, and so on. Every pipe in the main loop connects to its two neighbors (including <code>S</code>, which will have exactly two pipes connecting to it, and which is assumed to connect back to those two pipes).</p>
|
||||
<p>Here is a sketch that contains a slightly more complex main loop:</p>
|
||||
<pre><code>..F7.
|
||||
.FJ|.
|
||||
SJ.L7
|
||||
|F--J
|
||||
LJ...
|
||||
</code></pre>
|
||||
<p>Here's the same example sketch with the extra, non-main-loop pipe tiles also shown:</p>
|
||||
<pre><code>7-F7-
|
||||
.FJ|7
|
||||
SJLL7
|
||||
|F--J
|
||||
LJ.LJ
|
||||
</code></pre>
|
||||
<p>If you want to <em>get out ahead of the animal</em>, you should find the tile in the loop that is <em>farthest</em> 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 <em>along the loop</em> to reach from the starting point - regardless of which way around the loop the animal went.</p>
|
||||
<p>In the first example with the square loop:</p>
|
||||
<pre><code>.....
|
||||
.S-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
</code></pre>
|
||||
<p>You can count the distance each tile in the loop is from the starting point like this:</p>
|
||||
<pre><code>.....
|
||||
.012.
|
||||
.1.3.
|
||||
.23<em>4</em>.
|
||||
.....
|
||||
</code></pre>
|
||||
<p>In this example, the farthest point from the start is <code><em>4</em></code> steps away.</p>
|
||||
<p>Here's the more complex loop again:</p>
|
||||
<pre><code>..F7.
|
||||
.FJ|.
|
||||
SJ.L7
|
||||
|F--J
|
||||
LJ...
|
||||
</code></pre>
|
||||
<p>Here are the distances for each tile on that loop:</p>
|
||||
<pre><code>..45.
|
||||
.236.
|
||||
01.7<em>8</em>
|
||||
14567
|
||||
23...
|
||||
</code></pre>
|
||||
<p>Find the single giant loop starting at <code>S</code>. <em>How many steps along the loop does it take to get from the starting position to the point farthest from the starting position?</em></p>
|
||||
|
||||
<p>Your puzzle answer was <code>7066</code>.</p><p class="day-success">The first half of this puzzle is complete! It provides one gold star: *</p>
|
||||
<article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>You quickly reach the farthest point of the loop, but the animal never emerges. Maybe its nest is <em>within the area enclosed by the loop</em>?</p>
|
||||
<p>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:</p>
|
||||
<pre><code>...........
|
||||
.S-------7.
|
||||
.|F-----7|.
|
||||
.||.....||.
|
||||
.||.....||.
|
||||
.|L-7.F-J|.
|
||||
.|..|.|..|.
|
||||
.L--J.L--J.
|
||||
...........
|
||||
</code></pre>
|
||||
<p>The above loop encloses merely <em>four tiles</em> - the two pairs of <code>.</code> in the southwest and southeast (marked <code>I</code> below). The middle <code>.</code> tiles (marked <code>O</code> below) are <em>not</em> in the loop. Here is the same loop again with those regions marked:</p>
|
||||
<pre><code>...........
|
||||
.S-------7.
|
||||
.|F-----7|.
|
||||
.||<em>OOOOO</em>||.
|
||||
.||<em>OOOOO</em>||.
|
||||
.|L-7<em>O</em>F-J|.
|
||||
.|<em>II</em>|<em>O</em>|<em>II</em>|.
|
||||
.L--J<em>O</em>L--J.
|
||||
.....<em>O</em>.....
|
||||
</code></pre>
|
||||
<p>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, <code>I</code> is still within the loop and <code>O</code> is still outside the loop:</p>
|
||||
<pre><code>..........
|
||||
.S------7.
|
||||
.|F----7|.
|
||||
.||<em>OOOO</em>||.
|
||||
.||<em>OOOO</em>||.
|
||||
.|L-7F-J|.
|
||||
.|<em>II</em>||<em>II</em>|.
|
||||
.L--JL--J.
|
||||
..........
|
||||
</code></pre>
|
||||
<p>In both of the above examples, <code><em>4</em></code> tiles are enclosed by the loop.</p>
|
||||
<p>Here's a larger example:</p>
|
||||
<pre><code>.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...
|
||||
</code></pre>
|
||||
<p>The above sketch has many random bits of ground, some of which are in the loop (<code>I</code>) and some of which are outside it (<code>O</code>):</p>
|
||||
<pre><code><em>O</em>F----7F7F7F7F-7<em>OOOO</em>
|
||||
<em>O</em>|F--7||||||||FJ<em>OOOO</em>
|
||||
<em>O</em>||<em>O</em>FJ||||||||L7<em>OOOO</em>
|
||||
FJL7L7LJLJ||LJ<em>I</em>L-7<em>OO</em>
|
||||
L--J<em>O</em>L7<em>III</em>LJS7F-7L7<em>O</em>
|
||||
<em>OOOO</em>F-J<em>II</em>F7FJ|L7L7L7
|
||||
<em>OOOO</em>L7<em>I</em>F7||L7|<em>I</em>L7L7|
|
||||
<em>OOOOO</em>|FJLJ|FJ|F7|<em>O</em>LJ
|
||||
<em>OOOO</em>FJL-7<em>O</em>||<em>O</em>||||<em>OOO</em>
|
||||
<em>OOOO</em>L---J<em>O</em>LJ<em>O</em>LJLJ<em>OOO</em>
|
||||
</code></pre>
|
||||
<p>In this larger example, <code><em>8</em></code> tiles are enclosed by the loop.</p>
|
||||
<p>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:</p>
|
||||
<pre><code>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
|
||||
</code></pre>
|
||||
<p>Here are just the tiles that are <em>enclosed by the loop</em> marked with <code>I</code>:</p>
|
||||
<pre><code>FF7FSF7F7F7F7F7F---7
|
||||
L|LJ||||||||||||F--J
|
||||
FL-7LJLJ||||||LJL-77
|
||||
F--JF--7||LJLJ<em>I</em>F7FJ-
|
||||
L---JF-JLJ<em>IIII</em>FJLJJ7
|
||||
|F|F-JF---7<em>III</em>L7L|7|
|
||||
|FFJF7L7F-JF7<em>II</em>L---7
|
||||
7-L-JL7||F7|L7F-7F7|
|
||||
L.L7LFJ|||||FJL7||LJ
|
||||
L7JLJL-JLJLJL--JLJ.L
|
||||
</code></pre>
|
||||
<p>In this last example, <code><em>10</em></code> tiles are enclosed by the loop.</p>
|
||||
<p>Figure out whether you have time to search for the nest by calculating the area within the loop. <em>How many tiles are enclosed by the loop?</em></p>
|
||||
|
||||
Reference in New Issue
Block a user