add day 10 (stinky)
This commit is contained in:
parent
01432b8e0f
commit
4b59c0f893
7 changed files with 394 additions and 0 deletions
140
23/elixir/inputs/day10.txt
Normal file
140
23/elixir/inputs/day10.txt
Normal file
|
@ -0,0 +1,140 @@
|
|||
7.FF7777.|77.-L-77.|F-7-.L77|7F|7-|-JF77FFF777.7FL--F-F..F.-7-F7-J.FFF7JFF7-J7....FFJFL.|-L7F--|-L7L-|-|-|.F77F7F-|7---L-.7-.F-7F|-L77...-.-
|
||||
J7L-||LL7L|7-J.|.|7LL-|.F7|FJ7----J-7-|LLJ|JJ||LJL|L|-|.|J.LL-|F7|JFFJL7LFF7|J7-L|LJ-||FL-FLJ7L-7JFLFJ.-FL.||F|7.LJ|7J.L.77JFF.L-7J.LL--7--.
|
||||
.77L|7-|L-L7J.L7FJ.||F|F|-F-JJ.|..|LL-L.JJ|L-7JL|FL-|-J7J-FF|L||FFJF|77|LLL7.F7JLF7.L-|JJF7..F.F|F|-J.L-LL|-|7L-|-F|J7-L-F|-777|L|F7-L-77FJ7
|
||||
-777||LJ.|J|.--F7.7-LL|---JJ7.F-J-|JLF|-L--|7|.-JL7F7LL----FF7.F|JL|LJ-J7.FL7-.7F||7.|.L7F77F7F77F77LF7F7LL.-JF|.F||777.|F..||FF-JFJ7..L-|JJ
|
||||
F|F77F--7JL|7JFF--L..FJJ7FJFFF-77||F7FL-|LF--|LJ.|-J-7J|LJFLJL7|L7---JJ.--FJL.J7FJ|.L--F---7|LJL-JL7-J|JL.|F.F|FLJ7|F7FL7L|7FLJ-J7..FF.|J.L7
|
||||
FLJJFL|L7-FL--FLJ7L7-L|J|-7F-|FL-|JJFJJ7F7-J.F--F-JL-|-L7F-7FJ|LL--JL7F|J7|F|.LFJFJ...|L7F7|L-7F---JJF|7.FLJ7J||.L-JJLL7JL7--JLLLF7.J|L-7F.7
|
||||
F|L-7F7-|-JLLJ|F|L.L7LF-LL7L-L7-FL77L-L-J|.FL.7.LJ-F-JJFJJ7|JF|-J|.-JFF---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7L-J|
|
||||
-77FJ..|.F|F-----7J||FJ||F-J||L---JF--JF7LJLJF-JF7FJLJ|L7|L7F--JFJ|L7LJL7F--JFJ|F7|||||FJL7F--J|L7|L-7L-----JL-JLJ|F7F7F7L--7|||FJFF|.LLFJL7
|
||||
L-J|--F-7FLL--7F7L-JLJFJLJF7LJF7F7FL-7FJL---7L-7|||F77L-JF-J|F--JFJFJF7FJ|F7FJFJ|||||||L--JL-7FJ-LJF7L-----------7||LJLJL---JLJLJ7-LJ.|.JFFJ
|
||||
.FLJ7|LLF-JF7.LJL7F---JLF7|L--JLJL---J|F----JF7LJ|LJL---7|F7||F-7L7|FJLJLLJ||FJFJ|||||L-7F---JL7F--JL-----7F--7F7||L-------7J.||.7.|77FJ7|JF
|
||||
FLJ.J7-F|J-||7LF-J|F---7||L---------7FJL-7F--JL-7L7F7F--JLJLJLJFJFJ||F7F--7LJL7||LJLJ|F-JL--7F-JL---7F7F-7|L-7LJLJL--------JJJLF7LJ-F|.F-7|L
|
||||
-J|-7|F-F-7||F7L--JL7F7LJL--------7FJL7F-JL7F7F7|FJ||L--7F-----JFJFJLJLJF7||F-JL--7F-J|F7F-7LJF-----J|||FJ|F-J7F7F7F7|F-7F7F7JF||FL-F|.7J|L|
|
||||
|F7-77|FL7LJ|||FF7F7LJL7F--------7||F-JL---J|LJ||L7||F--JL----7FJ7L7F-7FJLJFJF--7FJL7FJ||L7L-7L7F--7FJLJL7LJF-7|||||L7|FJ|LJL--JL7-.7J-7L|7J
|
||||
F|F7JLF7FJF7LJL-JLJL---J|F-------JLJ|F--7F7FJF7LJFJ||L---7F---JL7F-JL7|L-7.|FJF-JL-7||FJL-JF7L7LJF7LJJF--JF7|FJ||||L7LJL-JF7F----JJ.77JL-.7J
|
||||
L-JF-FJ|L-JL--7F7F7F7F-7||F7F7F-----JL7FJ|LJFJL-7L7|L7F--JL-7F7FJ|F-7||F7L7|L7L-7F-J|||F7F7|L7|JFJL7F7L--7||||FJLJL-JF7F7FJ|L-7F-7F7F7LLL7F7
|
||||
|.FJ-L7L7.F7F7LJLJLJ||-||LJ||||F------JL7L-7|F--JFLJ|LJF7F--J||L7|L7||||L-JL7|F-JL-7LJLJLJLJ-|L-JF7LJL7F7||LJLJF--7F-JLJLJJL--J|FJ7LL-.LJ-||
|
||||
LF||.LL7L-J||||F7F--JL7LJJFJ|||L-------7|F7LJL-7F7-F---J|L7F7|L7||FJ|||L-7F7LJL-7F7|F---7F7F-JF-7|L7F7LJLJ|F---JF7LJF7LF7F7.F7FJL-7LLL-FJ7|7
|
||||
LL--L7JL--7|||FJ|L-7F7|7F-JFJLJLF---7F-J|||F7F-J|L7L7F-7|FJ||L7||||FJ||F7LJL---7||||L7F7LJLJF7|FJ|-LJ|F---JL----JL--JL-JLJ|FJLJF-7|7.LFF.F--
|
||||
FFJ.FFF--7||||L7|7FJ|LJFJF-J7F7FJF-7LJF7LJ|||L--JFJFJL7||L-JL7|||LJ|FJLJ|F---7FJ||LJ.LJL-7F7|LJL7|F-7LJF----7F--7F----7F-7LJF-7L7LJ77.FL||F7
|
||||
LJLF7|L-7LJ|||FJL7L-JF-JFJF--J|L-J.L--JL-7|||F7F7L-JF-JLJF---J||L7FJ|F--JL--7||FJL-7F----J|||F--J|L7L7-L---7|L-7|L--7.LJ7|F7L7L7|L|FL.FL7-LJ
|
||||
.|.|L--7L-7|||L-7|F7L|F7L7L--7|F7F7F-----JLJLJLJL7F7L7F7|L-7F7||FJL-J|F7F7F7||||F--JL---7FJ||L--7L7L7L-----JL--JL---JF--7|||FJLLJJL|.F7F-JL7
|
||||
F-.L-7FJFFJ|||.FJLJL7LJL-JLF7|||LJLJF----7LF7F7F7||L7LJL-7JLJLJ|L7LF7||LJ||||LJ|L7JF----J||LJF--JFJ.L7F-----------7F7|F-JLJLJF7JLF.J-7L|.FLF
|
||||
|LF--JL77L7||L7|F--7|F--7JFJLJLJF7F7|F---JFJLJLJ|||FJF---JJLF7FJFJFJLJL-7|||L-7|FJ-L7F---JF7FJF-7|F7FLJF----------J|||L7F7F7FJL7F77FL7-J7F.L
|
||||
L-L--7FJF7||L7LJL7-LJL-7L-JF----JLJLJL---7|F-7F-J||L7|F7F77F||L7L7L--7F-J||L7FJ|L-7.LJF---JLJFJFJ|||F--JF---7F-----JLJFJ|||||F-J||FF-LJF|777
|
||||
FJF--JL-JLJL7L7F7L7F7F7L--7|F------------J|L7|L7|LJFJLJLJL77|L7|FJF--JL-7|L7|L7|F-JFF7|F7F---JJL-J||L-7FJF--J|F-7F7F7FJFJLJLJL--J|7JL|FLJ.77
|
||||
F-JF-7F-7F-7L7LJL7LJ|||-F7LJL-7F-------7-FJFJ|FJF-7L7F--7FJFJFJLJ7L-7F7FJL7||FJLJLF-J|LJ||F-----7FJL7FJ|FJF7FJL7||||LJ7L7F---7F--JF7.|FJ-7J|
|
||||
|F7|FJL7LJLL7L7|L|F-J|L-J|F7F-J|F------JFJFJ7LJLL7|-|L7LLJFJFJJL|7|FLJLJJ-||LJJF7|L-7L-7LJL-7F-7LJF7LJFJL7|||F-JLJ|L----JL--7LJF--J|-JJ-F-.L
|
||||
LJLJL7FJ|F-7L7L7FJ|F7L--7LJLJF7|L--7F7F7|FJF7.F7FJL7L-JF7.|FJ||.F7J7.F|7JF||JJ.S|FJJL-7L7|F7LJ-L--JL--JF7LJLJ|F--7|F-----7F7L--JF7FJ.|.7LL|J
|
||||
|..F7LJF7|FJ-L7|L7||L7F7L----J||F--J|||LJ|7|L-JLJF-JLF7||FJL--7F77-J------LJ--FJL7JF7FJFJFJL--7F-------JL---7LJF-JLJF---7||L--7FJLJ|7|.F7F7|
|
||||
LF-JL77||||-F7||||||FJ|L7F-7F7LJL7F7|LJF7L7|F----JJF7|LJLJF7F-J|L7-|7JL|-|JL-.L-7|FJLJFJJL---7|L----------7FJF7L-7F7|F--J|L--7|L-7F77JLJFJJ-
|
||||
LL--7L7||||FJLJL-JLJL7|FJL7|||7F7LJLJF-JL7LJL--7F-7||L7F--JLJF-JFJJL77LL7|F7.|-FJ|L--7|F-7.F7||F---7F-----JL7|L7FJ|LJL--7|F7FJ|F7LJ|JJ-F-.|7
|
||||
|LJLL7LJLJ|L------7F-J||F7||||FJ|F---JF-7|F----J|FJ||J|L-----JF7L7-F-JJ|J.F7.-JL7|F--J|L7|FJ|||L--7|L-----7FJL7|L7|F----JLJLJ.LJ|F7|JLFF7FLJ
|
||||
F|77.L---7L7F-----JL-7|||||LJ|L7|L----JFJ|L-----JL-JL-JF7F--7FJL7L7|FL7|-F.F77F-JLJF-7|-||L7|||F--JL------JL--J|FJ||.F------7F7JLJLJ.FJJFJJ|
|
||||
F7F7F7F7FL7||F7F7F7F7LJLJ|L-7L-J|F--7F-JFJF7F-----7F7F7||L-7LJ-L|FJJ--JJ-|.||-L-7F7|FJL-J|FJLJLJF-7F--7F----7F-JL-JL-JF--7F-J||7J7FJ-J|F7L77
|
||||
|LJLJLJL--JLJ|||||LJ|F7F7L7FL--7|L-7LJF7L-JLJF7F7-LJLJLJ|F7L-7JJLJJL7F|J7JFJL-7LLJLJL---7|L--7F7L7LJF-J|7F7FJL-7F-----JF7LJF-JL77F|7JFJL|F--
|
||||
L7F---7F7F7F7|LJLJJFJ|LJL7L---7||F7L--JL-----JLJL-7F---7|||F-JF7J-|L--.L-.|F-7|F77F--7F7|L--7||L-JF7L-7|FJLJF7JLJF7LF--JL7FJF--J7-JF7J.LLJLL
|
||||
LLJF7L||||||||F----JFJ.F7L---7|||||F----------7F-7LJF--J||LJF-77LFL-7F77FLLJFJLJL7L-7LJLJF-7LJ|JF-JL--J|L7F7|L---JL-JF---J|FJJFF7|F||77L|.F.
|
||||
F--JL-J|||LJ||L7F7F7|F-JL----JLJLJLJF--------7||FJF7L-7FJL--JFJ7-||JLJFF|JLFJF--7L--JF7F7|FJF7L7L7F----JJLJLJF----7F7L----JL7JFJ|-F|L777F7|7
|
||||
L7F7F-7|LJF-J|FJ|||||L-7F---7F7F-7F7|F-------JLJL7||F-JL7F7F-JJ..F7-F.|-JJ.L7L7|L7F-7|LJLJL7||FJ7LJF7F7F----7L7F7LLJ|F7F-7F7L7|FJ-FJFJ.FJ|FJ
|
||||
|LJ||FJL-7L-7|L7|LJLJF7LJFF-J||L7LJLJL----------7LJLJ|LFJ|LJL|.F-||--|J-LLLJL-JF-J|LLJ-F7F7LJLJF---JLJ|L---7L7LJL--7||LJJLJL-J|L-7L7||7LLL|.
|
||||
7LFJ|L7F-JF7LJFJ|F---JL---JF-JL-JF--7F-7F7F7F7F-JF---7-L7|F7F7F7|||.|||JF7LFF--JF-JF---JLJ|F7F7L-----7L7JF-J7|F7F-7|LJF-7F----JF7|FJL-7J.LLL
|
||||
L|L-JJLJF7||F7L-JL---7F7F--JF7F7-L-7|L7LJLJLJ|L--JF--JF7LJ|||||L7|L-7L7FJ7LLL---JF7L-----7||||L7F---7L7L-JF-7|||L7|L-7L7LJF----JLJ|F--JFF-J|
|
||||
FJ|LF---JLJ|||F7F7LF-J|LJF--JLJL---JL7L7F7F77L---7L7F7||F7||||L7||F-JF-77L|.LF---JL7F----JLJ|L7|L--7|FJF--JFJLJ|FJL--JFJF-JF7F7-|FJL--7FF--7
|
||||
FJ|LL--7F-7LJ||||L7L--JF-JF7F---7F-7FL-J|LJL---7|L7LJLJ||||LJ|FJLJ||FJFJ7-|-FL----7|L---7F-7L-JL---J|L7|F-7L--7LJF7F-7L7|FFJ||L7FJF-7FJ-J.|-
|
||||
|F|7F-7LJ.L7FJ||L7|F7F7L--J||F--J|FL7F-7|F-----JF7L----J||L7FJL7F-JFJFJF-7F7FF7|F-JL----JL7L-7F7F--7L-J|L7L---JF7|||FJFJ|FJFJ|FJ|FJLLJJ-|7J|
|
||||
LFF7L7L---7|L-JL-JLJLJ|F--7LJL--7|F-J|FJ||F--7F-JL7F--7F||-||F7|L7L|FJ-|FJ|L-JL7L--7F-7F--JLFJ|||F-JF-7|-L-----J||||L7L7|L7|FJL7|||F7J7FLF-7
|
||||
-FJL-JF7F7LJF-7F7F7F--JL-7L--7F7LJL--JL-JLJF7||F--J|F-JFJL-J||||FJFJ|F7|L7L--7FJ7F7LJLLJF7LFJFJLJL7FJFJ|F-------J|||FJFJL-JLJF7||L-JL777.|-|
|
||||
LL--7FJLJL7FJJLJLJ|L7F-7.|F-7||L---------7FJ|||L--7|L-7L--7FJ|||L7L7LJ||FJF7FJ|F7|L7F7F7|L-JFJLF7.LJFJFJL---7F7F7||||FJF7F-7FJ|LJF--7L7J-F-.
|
||||
|FJ7LJ.F-7LJF--7F7L7|L7L7LJFJLJF---7F--7-LJFLJ|F--J|F-JF7FJL-JLJFJFJF-J|L7|||FJ||L7LJ||LJF7FJF7||F--JFJF--7FJ|||LJLJLJFJLJFJ|FJF7L-7|FJJJ.L-
|
||||
7JLF|F-L7L7FJF7LJL-JL7L7|F7L--7L7F7LJF-JF--7-FJL7F7|L-7||L7F----JFL7|F7|FJ||||FJ|.|F-JL--JLJ||LJ|L---JLL-7|L-JLJF7F--7L-7LL7||FJ|F7|LJJ..77|
|
||||
||.7L7.LL7LJFJL-7F7F7L7||||F--JFJ|L-7L--JF-JFJF7|||L-7|||FJL--7F--7|||||L7|LJLJFJFJL---7F---7L-7L-----7F-JL-----JLJF7L7FJF-J||L7LJLJJ.F-..L7
|
||||
FJ.JFF--7L-7|F--J|||L7LJLJLJF--J.L-7|F7F-JF-JFJ||||F7|||||F---J|F-J|LJLJFJL---7L7L7F---JL-7FJF7L-----7|L--------7JFJL7LJLL-7|L7L----7--|--J|
|
||||
JF7LFL-7L--J||F7FJ||FJF-7F-7|F7F---JLJ|L-7|F7L7LJ|||||||||L7F-7|L7-L7F--JF-7F7|FJFJL7F7F--JL7|L7.F7F-JL--------7L-JF7L--7F7||FJF----JJ7J|F-J
|
||||
F||FFJFL7F7FJLJ||.LJL-J|LJFLJ||L-----7|F-J||L7L7FJ||LJLJLJFJ|FJ|FJF7|L7F7L7||||L7L7FJ||L---7||FJFJ|L---7F7FF--7L---JL--7LJ|LJL7L7F|LJL7.|.L.
|
||||
--JJ-J|LLJ||F--JL7F----------JL------J|L--JL7L7LJFJL-7F--7|FJL7||FJLJFJ|L7|||||FJFJ|FJL-7F-JLJL-JFJF7F-J|L-JF7L------7|L-7L-7|L7|--7LFJFLLF7
|
||||
J-J||LL7LFLJL--7FJ|F7F7F-----7F-----7FL---7FJFL--JF7FJL7JLJL-7LJLJF--JFJFJ|||||L-JFJ|F--JL------7L-JLJF-JF--JL-------JF7|L7FJF7LJJ7|-|-7J|L7
|
||||
L|LJ7FL-.L.|F-7LJ7LJ||||F----JL7F---JF7F7LLJF-7F-7||L-7L---7|L7F-7L--7L7|FJ|||L-7FJFJL77F-------JF----JF7L-7F7F7F7F---JL7.LJFJL---77-L7-7-7J
|
||||
F|7F7F|-L.FFL7L7|F7-LJLJL-7F7F-JL----JLJL--7|FJ|FJ||F7|F---JF7LJL|F--JFJ|L7||L7-|L7L-7L7L--7F---7L7F---JL-7LJ||||||F----JF-7L7F---J|LL|7|-LJ
|
||||
L7-JJ||JLF7JLL7|FJL-7F7F7|LJ||F-7F----7F7F7||L-JL7|LJLJL7F-7||F7FJL7F7L7L7|||FJFJFJF-JFJF-7LJLF-JFJL7F-7F7L--J|||LJL-77F7|FJFJL-7J.F7JF7|.LJ
|
||||
-7.|..|..|F-F-J|L7F7LJLJL7F7LJL7||F--7LJ||||L-7F-JL--7F-J|FJ|||LJF-J||J|FJ|LJ|JL7L7|F-JFL7|LF7|F-JJL||7LJL----JLJF7F7L-JLJL-JF--JJ7J|JLL-7||
|
||||
|.|J.77L.F7FJF7L7LJL----7LJL7FFJ|LJF7L-7LJ||F-J|F7FF7||F-JL7|||F7|F-JL-JL-JF-JF-JFJ|L--7FJ|FJ|LJF77FJ|F---------7|LJL---7F7F-J-F7-|L77.7J|||
|
||||
7J-F-L--FJLJFJL7L7JF7F7JL7F7L-JFJF-JL--J|FJ|L-7LJ|FJLJLJF--J||LJ||L--7F7F--JF7L-7L7|F--JL7|L7|F7|L7L-JL-------7FJL-----7|||L---J|L--L|F7--J-
|
||||
.JL|7..LL---JF7|FJFJLJL7|LJL-7FJLL----7F7L7|F7|F-JL--7F7L7F7|L7FJ|F-7LJ|L-7FJ|F-JFJ|||F7FJ|FJ|||L7|F7F------7FJL-7F----JLJ|F7F-7L7J7|J|J7FJ7
|
||||
F-FL7LF---77FJLJL7L---7L---7FJL-7F7F-7LJ|.LJ|||L-77F7LJL7||||FJL7||FJF-JF-JL7LJF-JFJL7||L7|L7||L7|LJ|L-----7|L--7|L-7F---7|||L7|FJJL-FJ7L7|7
|
||||
LFL-F7L7F7L-JF-7FJF--7L---7LJF-7LJLJLL--JF7FJ||F-JFJL-7F|||LJL7FJLJL7L-7L7F7L-7L7FJF-J|L7|L7||L7||F-JF-----JL-7FJ|F7||F7FJLJ|FJLJJ7|LJ-F--J7
|
||||
F|JJLL-LJL7F-JFJL-JF7L----JF7|FJF7F--7LF7||L7LJ|F7L7F-JFJ||F--JL-7F-JFFJFJ||F7|FJ|FJF7L7||FJ||FJ|||F7L-------7LJJLJLJ||LJF7LLJF7J7|JJL7L||F-
|
||||
7|-7.|FLLFJ|F-JF7F-JL7F7F-7|||L7|LJF-JFJ||L7|F7|||FJ|F7L7|||F--7FJL--7L7L7|||||L-JL7|L7|||L7||L7|||||F7F----7L-7F---7|L--JL7F7||7FFJJF-7|-JJ
|
||||
LJ.LF-|.FL-JL7FJ||F--J|LJ7||||FJ|F-JF7|FJ|FJLJ|||||FJ||7|||||F-JL7F--J7|FJ||||L--7FJL7||||FJ||F||||||||L---7L--J|F-7LJF7F7FJ|LJL-7JJ.|.LJF7.
|
||||
FJ.7JF--7|F7FJ|FJ||F7FJJF-J|LJL-JL-7|||L7||F7FJ|||||FJ|FJ||||L7F7||F-7FJL7|||L--7||F7|||LJL7|L7|||LJ|||F7F-JLF77|||L7FJLJ|L-JF7F-J.LF7-|-|F|
|
||||
|F-L|L-7L-JLJFJL7|LJ||F-JF-JF------J|LJ-|||||L7|||||||||FJ|LJFJ|||||J||F-J||L-77LJLJ||LJF--J|FJ|||F-J|||||JF-JL-JL-7|L-7||F--J|L7J7.L|F7-L||
|
||||
|L|||FL|F7F--J|-LJF-J|L7FJF7|F7F-7F7|.F-J|||L-JLJ||LJFJ|L7L-7|FJLJ||FJ||F7||F7|F----JL-7|F-7|L7|||L-7|LJ|L-JF-7F7F-JL--JFJL--7L-J.L|.L-|--L7
|
||||
||F7L7L||||7|JF---JF7|FJ|FJLJ||L7LJ|L7L-7||L--7F-JL-7|FJFJF7||L--7LJL7|||||||||L7F7F7F7|LJLLJFJ|||-FJL-7|F7FJ-|||L--7F-7L----J7||-J.FF-|7J--
|
||||
777JFJ|LJLJJ||L----JLJL-JL7F-J|FJF-JFJF-J|L---JL-7F7||L7|FJ|||F--JF7F||||||LJ|L7||LJ|||L-77F-JFJLJFJF7FJLJ||F7LJL7F-J|FJF7F7.|L-7|.L-J|LF77.
|
||||
LFL---F|-LJLF------7JF----JL7FJL7L-7|FJF7L------7||||L-J||JLJ|L-7FJL-J||||L-7|FJLJJFJ||F7|FJF7L7F-JFJ|L-7FJLJL--7|L--JL-JLJL7F|JL7.|L|L7LJ-7
|
||||
||L7|.L.|L7-L7F-7F7L-JF-7F7FJL7FJF7LJL7|L7F7F-7FJ||||F--JL-7FJF-JL-7F7|LJ|F-JLJF7F-JFJ||||L7|L-J|F-J|L7FJL7F-7F7|L-7F---7F-7L7LF-J77L|-LFJ.-
|
||||
FJLFF7FF|JF--J|-LJL--7|J||||F-J|FJL---JL7||||-LJ7||||L-7F7FJL7L--7FJ||L-7|L----J|L7FJ|LJLJFJ|F--J||F--J|F-JL7LJLJF-JL--7|L7L-J-J.LFJ--7LJFJ.
|
||||
FJFL-7FFJF|F--JF-----JL7LJ||L-7||F7F7F7FJ|||L---7LJ||F-J||L7|L7F-JL7|L7FJ|F----7|FJL----7F|FJL-7FJFJF7FJL7F7L---7L-----J|FJJ.LF7.L|--FJF|7LJ
|
||||
F7JLL|7L-JLJF--JF7F7F7FJF-J|F-J|LJLJ||LJ7|||F7F7L-7LJL-7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L-7J|-7|-F||-7LJ7L7L|7-FLFF-7L|.LLJJJJ.|J|.7F|7F-JF7--|.L||F|LJ-FLJFL-7
|
||||
F|-LJ|FJJF-J|.L|J7J.LJ|J.L|7..|LLFJ7L||-L7|.LLJ.FL|-|J.L|F-|7|.||FF-L--J---JF--7JF7-||JFJLJ.FFLJ.-7LJ-L7.7--F7JLF7L-|F7JLJ..F7L7JLFLLF7FLF|J
|
||||
F|-|.-JL--7F-7F|FL77|.-.FLF7.L|FFJFL-|J..LJ-FJ7L-.J-7.7-J.LLL-JJJF||.L|LLFL7LF..F7.F|L-7|J|--J|L.|7L|J|F||F7|F7LJ|-LFF-J|7LLJJ7||-J|LLJ7-77.
|
||||
LL-JJJ.7JL7J.|-.L--77-L|JLFJ7.L-7JL.L|J.--7.L-JJJ.L.L7--LJ-|JJLLFFJJ-LL-7JLL.J-L-.F-7JJFF.L-LJL-77-F--J-L7L-LLL-LLJ.JJ|LF-J--JLFL.7JJLLJ-L.F
|
5
23/elixir/inputs/day10_example1.txt
Normal file
5
23/elixir/inputs/day10_example1.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
-L|F7
|
||||
7S-7|
|
||||
L|7||
|
||||
-L-J|
|
||||
L|-JF
|
5
23/elixir/inputs/day10_example2.txt
Normal file
5
23/elixir/inputs/day10_example2.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
7-F7-
|
||||
.FJ|7
|
||||
SJLL7
|
||||
|F--J
|
||||
LJ.LJ
|
9
23/elixir/inputs/day10_example3.txt
Normal file
9
23/elixir/inputs/day10_example3.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
...........
|
||||
.S-------7.
|
||||
.|F-----7|.
|
||||
.||.....||.
|
||||
.||.....||.
|
||||
.|L-7.F-J|.
|
||||
.|..|.|..|.
|
||||
.L--J.L--J.
|
||||
...........
|
10
23/elixir/inputs/day10_example4.txt
Normal file
10
23/elixir/inputs/day10_example4.txt
Normal 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...
|
10
23/elixir/inputs/day10_example5.txt
Normal file
10
23/elixir/inputs/day10_example5.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
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
|
215
23/elixir/lib/days/day10.ex
Normal file
215
23/elixir/lib/days/day10.ex
Normal file
|
@ -0,0 +1,215 @@
|
|||
defmodule AOC.Day10 do
|
||||
# use AOC.Day, day: 10, input: "example5"
|
||||
use AOC.Day, day: 10
|
||||
|
||||
def parse_input(lines) do
|
||||
pipe_map =
|
||||
lines
|
||||
|> Enum.with_index()
|
||||
|> Enum.flat_map(fn {row, y} ->
|
||||
row
|
||||
|> String.to_charlist()
|
||||
|> Enum.with_index()
|
||||
|> Enum.map(fn {tile, x} -> {{y, x}, tile} end)
|
||||
end)
|
||||
|> Enum.into(%{})
|
||||
|
||||
connection_map =
|
||||
Enum.map(pipe_map, fn {coords, tile} ->
|
||||
connections =
|
||||
case tile do
|
||||
?| -> [:north, :south]
|
||||
?- -> [:east, :west]
|
||||
?L -> [:north, :east]
|
||||
?J -> [:north, :west]
|
||||
?7 -> [:south, :west]
|
||||
?F -> [:south, :east]
|
||||
?. -> []
|
||||
?S -> []
|
||||
end
|
||||
|
||||
{coords, connections}
|
||||
end)
|
||||
|> Enum.into(%{})
|
||||
|
||||
{start_location, start_connections} = find_start_connections(pipe_map)
|
||||
|
||||
{pipe_map, connection_map, start_location, start_connections}
|
||||
end
|
||||
|
||||
def find_start_connections(pipe_map) do
|
||||
{start_y, start_x} =
|
||||
start_location =
|
||||
pipe_map
|
||||
|> Enum.find(&(elem(&1, 1) == ?S))
|
||||
|> elem(0)
|
||||
|
||||
start_connections =
|
||||
[
|
||||
{{start_y - 1, start_x}, ~c"|7F"},
|
||||
{{start_y, start_x + 1}, ~c"-J7"},
|
||||
{{start_y + 1, start_x}, ~c"|LJ"},
|
||||
{{start_y, start_x - 1}, ~c"-LF"}
|
||||
]
|
||||
|> Enum.filter(&Map.has_key?(pipe_map, elem(&1, 0)))
|
||||
|> Enum.filter(fn {coords, allowed_pipes} ->
|
||||
pipe = Map.fetch!(pipe_map, coords)
|
||||
Enum.member?(allowed_pipes, pipe)
|
||||
end)
|
||||
|> Enum.map(&elem(&1, 0))
|
||||
|
||||
{start_location, start_connections}
|
||||
end
|
||||
|
||||
def find_furthest_pipe(connection_map, start_location, start_connections) do
|
||||
:ets.insert(:pipe_distances, {start_location, 0})
|
||||
Enum.each(start_connections, &visit_pipe(connection_map, &1, 1))
|
||||
|
||||
:ets.tab2list(:pipe_distances)
|
||||
|> Enum.map(&elem(&1, 1))
|
||||
|> Enum.max()
|
||||
end
|
||||
|
||||
def visit_pipe(connection_map, {y, x} = location, step_count) do
|
||||
case Map.fetch(connection_map, location) do
|
||||
{:ok, directions} ->
|
||||
location_step_count =
|
||||
case :ets.lookup(:pipe_distances, location) do
|
||||
[{_, location_step_count}] -> location_step_count
|
||||
_ -> :infinity
|
||||
end
|
||||
|
||||
if step_count < location_step_count do
|
||||
:ets.insert(:pipe_distances, {location, step_count})
|
||||
|
||||
Enum.each(directions, fn
|
||||
:north -> visit_pipe(connection_map, {y - 1, x}, step_count + 1)
|
||||
:east -> visit_pipe(connection_map, {y, x + 1}, step_count + 1)
|
||||
:south -> visit_pipe(connection_map, {y + 1, x}, step_count + 1)
|
||||
:west -> visit_pipe(connection_map, {y, x - 1}, step_count + 1)
|
||||
end)
|
||||
end
|
||||
|
||||
:error ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
def part1({_, connection_map, start_location, start_connections}) do
|
||||
:ets.new(:pipe_distances, [:set, :protected, :named_table])
|
||||
|
||||
find_furthest_pipe(connection_map, start_location, start_connections)
|
||||
end
|
||||
|
||||
def count_enclosed(pipe_map, connection_map, start_location, start_connections) do
|
||||
next_location = tl(start_connections) |> hd()
|
||||
# next_location = hd(start_connections)
|
||||
|
||||
count_enclosed(pipe_map, connection_map, start_location, start_location, next_location)
|
||||
end
|
||||
|
||||
def count_enclosed(
|
||||
pipe_map,
|
||||
connection_map,
|
||||
start_location,
|
||||
{prev_y, prev_x} = previous_location,
|
||||
{y, x} = current_location
|
||||
) do
|
||||
if current_location != start_location do
|
||||
directions = Map.fetch!(connection_map, current_location)
|
||||
|
||||
# Always take RIGHT hand side
|
||||
|
||||
if Enum.member?(directions, :east) and Enum.member?(directions, :west) do
|
||||
if prev_x < x do
|
||||
# We came from the east
|
||||
flood_fill_ground(pipe_map, start_location, {y + 1, x})
|
||||
else
|
||||
# We came from the west
|
||||
flood_fill_ground(pipe_map, start_location, {y - 1, x})
|
||||
end
|
||||
end
|
||||
|
||||
if Enum.member?(directions, :north) and Enum.member?(directions, :south) do
|
||||
if prev_y < y do
|
||||
# We came from the north
|
||||
flood_fill_ground(pipe_map, start_location, {y, x - 1})
|
||||
else
|
||||
# We came from the south
|
||||
flood_fill_ground(pipe_map, start_location, {y, x + 1})
|
||||
end
|
||||
end
|
||||
|
||||
if Enum.member?(directions, :north) and Enum.member?(directions, :east) and prev_y < y do
|
||||
flood_fill_ground(pipe_map, start_location, {y, x - 1})
|
||||
flood_fill_ground(pipe_map, start_location, {y + 1, x})
|
||||
end
|
||||
|
||||
if Enum.member?(directions, :east) and Enum.member?(directions, :south) and prev_x > x do
|
||||
flood_fill_ground(pipe_map, start_location, {y - 1, x})
|
||||
flood_fill_ground(pipe_map, start_location, {y, x - 1})
|
||||
end
|
||||
|
||||
if Enum.member?(directions, :south) and Enum.member?(directions, :west) and prev_y > y do
|
||||
flood_fill_ground(pipe_map, start_location, {y, x + 1})
|
||||
flood_fill_ground(pipe_map, start_location, {y - 1, x})
|
||||
end
|
||||
|
||||
if Enum.member?(directions, :west) and Enum.member?(directions, :north) and prev_x < x do
|
||||
flood_fill_ground(pipe_map, start_location, {y + 1, x})
|
||||
flood_fill_ground(pipe_map, start_location, {y, x + 1})
|
||||
end
|
||||
|
||||
next_location =
|
||||
Enum.map(directions, fn
|
||||
:north -> {y - 1, x}
|
||||
:east -> {y, x + 1}
|
||||
:south -> {y + 1, x}
|
||||
:west -> {y, x - 1}
|
||||
end)
|
||||
|> Enum.reject(&(&1 == previous_location))
|
||||
|> hd()
|
||||
|
||||
count_enclosed(pipe_map, connection_map, start_location, current_location, next_location)
|
||||
end
|
||||
end
|
||||
|
||||
def flood_fill_ground(pipe_map, start_location, {y, x} = location) do
|
||||
if location != start_location do
|
||||
case Map.fetch(pipe_map, location) do
|
||||
{:ok, _} ->
|
||||
case :ets.lookup(:pipe_distances, location) do
|
||||
[] ->
|
||||
case :ets.lookup(:enclosed_pipes, location) do
|
||||
[] ->
|
||||
:ets.insert(:enclosed_pipes, {location, 1})
|
||||
|
||||
[{y - 1, x}, {y, x + 1}, {y + 1, x}, {y, x - 1}]
|
||||
|> Enum.each(&flood_fill_ground(pipe_map, start_location, &1))
|
||||
|
||||
_ ->
|
||||
:ok
|
||||
end
|
||||
|
||||
_ ->
|
||||
:ok
|
||||
end
|
||||
|
||||
_ ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def part2({pipe_map, connection_map, start_location, start_connections}) do
|
||||
:ets.new(:enclosed_pipes, [:set, :protected, :named_table])
|
||||
|
||||
count_enclosed(pipe_map, connection_map, start_location, start_connections)
|
||||
|
||||
:ets.tab2list(:enclosed_pipes)
|
||||
|> Enum.count()
|
||||
|> IO.inspect()
|
||||
|
||||
"TODO"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue