aboutsummaryrefslogtreecommitdiffstats
path: root/src/13
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-04-07 17:18:18 -0400
committerLouis Burda <quent.burda@gmail.com>2023-04-07 17:19:39 -0400
commit87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch)
treecd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/13
parent1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff)
downloadaoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz
aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip
Reorder days into src
Diffstat (limited to 'src/13')
-rw-r--r--src/13/input150
-rw-r--r--src/13/part1188
-rw-r--r--src/13/part226
-rw-r--r--src/13/solve.py148
-rw-r--r--src/13/test17
5 files changed, 519 insertions, 0 deletions
diff --git a/src/13/input b/src/13/input
new file mode 100644
index 0000000..f970d12
--- /dev/null
+++ b/src/13/input
@@ -0,0 +1,150 @@
+ /----------------------------------------------------------------------------------------------\
+ /------------+-----\ /--------------------+-----------------\
+ | | | /-------------------->-------+<-------------------+------\ /+-------------\
+ | | | /---+------\ | | | || |
+ | | | /--+---+------+---------------------+--------------------+------+---------++---\ /------+----\
+ | | | | | | | /-----------+--------------------+------+---------++\ | | | |
+ | | | /----------------\ | | | | | | /----+------+---------+++--+--+------+----+\
+ | | | | /-------------+---------+--+---+------+---------+-----------+-----\ | | | ||| | | | ||
+ | | | | | | | | | /----+---------+-----------+-----+---------+----+----->+----\ ||| | | | ||
+ | | | | | | | | | | | /----+-----------+-----+---------+----+------+----+----+++--+\ | | ||
+ | | | | | | /---+--+---+-+----+\ | | | | | | | | ||| || | | ||
+ | | | | | | | | | | |/---++---+----+-----------+-----+---------+--\ | | | ||| || | | ||
+ | | | | | | | | | | || || | | | | | | | | | ||| || | | ||
+ | | /-+----+--+-------------+---\ | | | | || ||/--+----+-----------+-----+---------+--+-+----\ | | ||| || | | ||
+ | /----------+---+-+----+--+-------------+---+-+---+--+---+-++---+++--+----+-----------+-----+------\ | | | | | | ||| || | | ||
+ | | | | | | | | | | | | | || ||| | | | | | | | | | | | ||| || \------+----/|
+ | | | | | | | |/--+-+---+--+---+-++---+++--+----+-----------+-----+------+--+--+-+----+-+<---+----+++\ || | |
+ | | /+---+-+----+--+-------------++-\| | | | | || ||| | | /-------+-----+------+--+<-+-+-\ | | | |||| || | |
+ | | || | | | | || || | | | | || ||| | | | | | | | | | | | |/---+----++++-++----\ | |
+ |/+--------\|| | | | /+-----------\ || || | | | | || ||| | | | | /-+------+--+--+-+-+--+-++---+----++++-++----+---+--\ |
+ ||| ||| | | | || | || || | | | | || ||| | | | /---+---+-+------+--+--+-+-+--+-++---+----++++-++----+-\ | | |
+ ||| ||| | | | || /--+-++-++-+---+\ | /+-++---+++--+----+---+---+---+---+>+------+--+--+-+-+--+-++---+-\ |||| || | | | | |
+ ||| /-+++---+-+\ | || | | || || \---++-+--++-++---+/| | | | | | | | | | | | | | || | | |||| || | | | | |
+ ||| | ||| | || |/++--------+--+-++-++-----++-+--++-++---+-+--+----+---+---+---+---+-+\ | | | | | | || | | |||| || | | | | |
+ ||| | ||| | || |||| | | || || || | |\-++---+-+--+----+---+---+---+---+-++-----+--+--+-+-+--+-/| | | |||| || | | | | |
+ ||| | ||| \-++---++++--------+--+-++-+/ || | | || | | | | | | | | || | | | | | | | /-+-+--++++-++----+-+-+--+\ |
+ ||| | ||| || |||| | | || | /-++-+--+--++---+-+--+----+---+---+---+---+-++-\ | | | | | | | | | | |||| || | | | || |
+ ||| /+-+++-----++---++++--------+--+-++-+----+-++-+--+--++---+-+--+----+---+---+---+---+-++-+---+--+\ | | | | | | | | \+++-++----+-+-/ || |
+ ||| || ||\-----++---++++--------+--+-++-+----+-++-+--+--++---+-+--+----+---+---+---+---+-++-+---+--++-+-/ | | | | | | ||| || | | || |
+ ||| || || /-++---++++--------+--+-++-+----+-++-+--+--++---+-+--+----+---+---+---+---+-++-+---+--++-+---+--+--+-+-+-+--\||| || | | || |
+ ||| || || | || |||| | | || | | || | | || | | | | /+---+---+---+-++-+---+--++-+---+--+--+-+-+-+--++++-++----+-+----++\|
+ ||| || || | || |||| | | || | | ||/+--+--++---+-+--+----+\ || | | | || | | || | | | | | | | |||| || | | ||||
+ ||| || || | || /-++++--------+--+-++-+----+-++++--+--++---+-+--+----++-++---+---+---+-++\| | || | | | | | | | |||| || | | ||||
+ ||| |\-++----+-+/ | |||| /---+--+-++-+----+-++++--+--++---+-+--+----++-++---+---+---+-++++---+\ || | | | | | | | |||| || | | ||||
+ ||| | || | | | |||| | | | || | | |||| | || | | | || || | | | |||| || || | | /+--+-+-+\| |||| || | | ||||
+ ||| | || | | | |||| | | | || | | |||| | || | | | || || | | | |||| || || | | || | | ||| |||| || | | ||||
+ ||| | || /--+-+--+-++++----+---+--+-++-+----+-++++--+--++---+-+--+----++-++---+---+---+-++++---++-++-+---+-++\ | | ||| |||| || | | ||||
+/--+++-----+--++-+--+-+--+-++++----+---+--+-++-+----+-++++--+--++---+-+--+--\ || || | | /-+-++++---++-++-+---+-+++-+-+-+++--++++-++---\| | ||||
+| ||| | || | \-+--+-++++----+---+--+-++-+----+-++++--+--++---+-+--+--+-++-++---+---+-+-+-++++---++-++-+---+-+++-+-+-+++--/||| || || | ||||
+| ||| | || | /-+--+-++++----+---+--+-++-+----+-++++--+--++-\ | | | | || || | |/+-+-++++---++-++-+---+\||| | | ||| ||| || || | ||||
+| ||| | || | | | | |||| | |/-+-++-+----+-++++--+--++-+-+-+--+--+-++-++---+---+++-+-++++---++-++-+\ ||||| | | ||| ||| || || | ||||
+| /+++-----+--++-+--+-+--+-++++----+---++-+-++-+----+-++++--+--++-+-+-+--+--+-++-++---+---+++-+-++++---++\|| || ||||| | | ||| ||| || || | ||||
+| |||| | || | | | | |||| | || | || | | \+++--+--++-+-+-+--+--+-++-++---+---+++-+-++++---+++++-++--+++++-+-+-+++---+++-/| || | ||||
+| |||| \--++-+--+-+--+-++++----+---++-+-++-+----+--+++--+--++-+-+-+--+--+-++-++---+---+++-+-++++---++++/ || ||||| | | ||| ||| | || | ||||
+| |||| || | | | | |||| | || | ||/+----+--+++-\| || | | | | | || || |/--+++-+-++++\ |||| || ||||| | | ||| ||| | || | ||||
+| |||| || | | | | |||| | || | ||||/---+--+++-++--++-+>+-+--+--+-++-++---++-\||| | ||||| |||| || ||||| | | ||| ||| | || | ||||
+| |||| || | | | | |||| | || | ||||| | ||| |\--++-+-+-+--+--+-++-++---++-++++-+-+++++--++++--++--+++++-+-+-++/ ||| | || | ||||
+| |||| || | | | | |||| | || | ||||| | ||| | || |/+-+--+--+-++-++---++-++++-+-+++++--++++--++--+++++-+-+-++\ ||| | || | ||||
+| |||| /++-+--+-+--+-++++----+---++-+-+++++---+-\||| | || ||| | | | || || || |||| | ||||| |||| || ||||| | | ||| ||| | || v ||||
+| |||| /----+++-+--+-+--+-++++----+---++-+-+++++---+-++++-+---++-+++\| | | \+-++---++-++++-+-+++++--++++--++--+++++-+-+-+++---+/| | || | ||||
+| |||| |/---+++-+--+-+--+-++++----+---++-+-+++++---+-++++-+---++-+++++--+--+--+\|| || |||| | ||||| |||| || ||||| | | ||| | | | || | ||||
+| |||| || ||| | | | | |||| | || | |||||/--+-++++-+---++-+++++--+--+--++++---++-++++-+-+++++--++++-\|| ||\++-+-+-+/| | | | || | ||||
+| |\++--++---+++-+--+-/ | |||| | \+-+-++++++--+-+/|| |/--++-+++++--+--+--++++---++-++++-+-+++++--++++-+++--++-++-+-+-+-+---+-+--+-\ || | ||||
+| | || || ||| | | | |||| | | | |||||| | | || || || ||||| | | |||| || ||\+-+-+++++--++++-+++--+/ || | | | | | | | | || | ||||
+| | || ||/--+++-+--+----+-++++----+----+-+-++++++--+-+-++-++--++-+++++--+--+-\|||| || || | | ||||| |||| ||| | || | | | | | | | | || | ||||
+| | || ||| ||| | | | |||| | | | |||||| | | || || || ||||\--+--+-+++++---++-++-+-+-+++++--++++-+++--+--/| | | | | | | | | || | ||||
+| | \+--+++--+/| | | | |||| | | | |||||| | | || || || |||| | | ||||| || |\-+-+-+++++--++++-+++--+---+-+-+-+-+---/ | | | || | ||||
+| | | ||| | | | | | |||| | | | ||||||/-+-+-++-++--++-++++---+--+-+++++---++-+--+-+-+++++--++++-+++--+---+-+\| | | | | | || | ||||
+| | | ||| | | | \----+-++++----+----+-+-+++++++-+-+-++-++--++-/||| | | ||||| ||/+--+-+-+++++--++++-+++\ | | ||| | | | | | || | ||||
+| | | ||| | | | | |||| | | | ||\++++-+-+-++-/|/-++--+++---+--+-+++++-\ |||| /+-+-+++++--++++-++++-+---+-+++\| | | | | || | ||||
+| | | /+++--+-+-+-------+-++++----+----+-+-++-++++-+-+-++--++\|| ||| | | ||||| | |||| || | ||||| |||| |||| | | ||||| | | |/+-++-+---\||||
+| | | |||| | | | | |||| | | | || |||| | | || ||||| ||| | | ||||| | |||| || | ||||| |||| |||| | | ||||| | | ||| || | |||||
+| | | |||| | | | | |||| | | | || |||| | | || ||||| ||| | | ||||\-+-++++-++-+-+++++--++++-++++-/ | ||||| | | ||| || | |||||
+| | | |||| | | | | |||| | | | || |||| | | || ||||| ||| | | |||| | ||||/++-+-+++++--++++-++++-----+-+++++-+--\/-+--+++-++-+--\|||||
+| | | |||| | | | | |||| | | | || |||| | | || ||||| ||| | | |||| | |\+++++-+-++++/ |||\-++++-----+-+++++-+--++-+--+++-++-+--+++++/
+| | | |||| | | | /-+-++++----+--\ | | || |||| | | || ||||| ||| |/-+-++++--+-+-+++++-+\|||| ||| |||| | ||||| | || | ||| || | |||||
+| | | |||| | | | | | |||| | | | | || |||| | | || ||||| ||| || | |||| | | ||||| |||||| ||| |||| | ||||| | || | ||| || | |||||
+| | | |||| | | | | | \+++----+--+-+-+-/| |||| | | || ||||| ||| || | |||| | | ||||| |||||| ||| |||| | ||||| | || | ||| || | |||||
+| | | |||\--+-+-+-----+-+--+++----+--+-+-+--+-++++-+-+-++--+++++--+++---++-+-/||| |/+-+++++-++++++---+++\ |||| | ||||v | || | ||| || | |||||
+| | | ||| | | | | | ||| | | |/+--+-++++-+-+\|| ||||| ||| || | ||| ||| |||||/++++++---++++-++++-----+-+++++-+--++-+-\||| || | |||||
+| | | ||| | | |/----+-+--+++\ | | ||| | ||\+-+-++++--+++++--+++---++-+--+++--+++-++++++++++++---++++-/||| /+-+++++-+--++-+-++++-++-+-\|||||
+| | | ||| | | || | | |\++---+--+-++/ | || | | |||| ||||\--+++---++-+--+++--+++-++++++++++++---++++--/|| || ||||| | || | |||| || | ||||||
+|/+--+-+++---+-+-++----+-+--+-++---+--+-++---+-++-+-+-++++--++++---+++---++-+--+++--+++-++++++++++++-\ |||| || || ||||| | || | |||| || | ||||||
+||| | ||| | | || /-+-+--+-++---+--+-++---+-++-+-+-++++--++++-\ ||| || | |||/-+++-++++++++++++-+-++++---++----++-+++++-+--++-+\|||| || | ||||||
+^|| | ||| | | || | | | | || | | || \-++-+-+-++++--++++-+-+++---++-+--++++-+++-++++++++++++-+-++++---++----++-+++++-+--++-/||||| || | ||||||
+||| | ||| | | || | | | | || |/-+-++-----++-+-+-++++--++++-+-+++---++-+--++++-+++>++++++++++++-+-++++---++----++-+++++-+\ || ||||| || | ||||||
+||| | \++---+-+-++--+-+-+--+-++---++-+-++-----++-+-+-++++--++/| | ||| || | |||| ||| \+++++++++++-+-++++---+/ || ||||| || |\--+++++-++-+-+/||||
+||| | || | | || | | | | || || | || || | | |||| || | |/+++---++-+--++++-+++--+++++++++++-+-++++\ | || ||||| || | ||||| || | | ||||
+||| | || | | || | | | | || || | || /++-+-+-++++--++-+-+++++--\|| | |||| ||| ||||||||||| | ||||| | /---++-+++++-++-+---+++++\|| | | ||||
+||| | || | | || | | | | || || | || ||| | | |||| || | ||||| ||| | |||| ||\--+++++++++++-+-+++++--+-+---++-+++++-++-+---++++++++-/ | ||||
+||| | || | | || /+-+-+--+-++---++-+-++----+++\| | |||| || | ||||| |\+-+--++++-++---+++++++++++-+-+++++--+-+---++-+++++-++-+---++/||||| | ||||
+||| | || |/+-++-++-+-+--+-++---++-+-++----+++++\| |||| || | ||||| | | | |||| || ||||||||||| | ||||| | | || ||||| || | || ||||| | ||||
+||| | || ||| || || | | | || || | || ||||||| |||| |\-+-+++++--+-+-+--++++-/| ||||||||||| | ||||| | | || ||||| || | || ||||| | ||||
+||| | || |||/++-++-+-+--+-++---++-+-++----+++++++-++++--+--+-+++++--+-+-+--++++--+---+++++++++++\| ||||| | | || ||||| || | || ||||| | ||||
+||| | || |||||| || |/+--+-++---++-+-++----+++++++-++++--+--+-+++++--+-+-+--++++--+-\ v|||||||||||| ||||| | | || ||||| || | || ||||| | ||||
+||| | || |||||| || ||| | || || | || ||||||| |||| | | ||||| | | | |||| | | |||||||||||||/+++++--+-+---++-+++++-++-+---++-+++++---+-++++\
+||| | || |||||| || |||/-+-++---++\| || ||||||| |||| | \-+++++--+-+-+--++++--+-+-+++++++++++++++++++--+-+---++-++++/ || | || ||||| | |||||
+||| | || |||||| || |||| | || |||| || ||||||\-++++--+----+++++--+-+-+--++++--+-+-++++++++++/|||||||| | | || |||| || | || ||||| | |||||
+||| | || |||||| || |||| | || |||| || |||||| |||| | ||||| | | | |||v \-+-++++++++++-++++++/| | | || |||| || | || ||||| | |||||
+||| | || /++++++-++\|||| |/++---++++-++----++++++--++++--+----+++++--+-+-+--++++----+-++++++++++-++++++-+--+-+---++-++++--++-+\ || ||||| | |||||
+||| | || |\+++++-+++++++-++++---++++-++----++++++--/||\--+----+++/| | | | |||| | |||||\++++-++++++-+--+-+---++-++++--++-++--++-+++++---+-+/|||
+||| | || | ||||| ||||||| |||| |||| || /-++++++---++---+----+++-+--+-+-+--++++----+-+++++-++++-++++++-+--+-+---++-++++--++\|| || ||||| | | |||
+||| | || | ||||| ||||||| |||| |||| || | |||||| || | ||| | | | | |||| | ||||\-++++-++++++-+--+-+---++-++++--+++++--+/ ||||| | | |||
+||| \--++--+-+++++-+++++++-++++---++++-++--+-++++++---++---+----+++-+--+-+-+--++++----+-++++--++++-+++/|| | | | || |||| ||||| | ||||| | | |||
+||| /---++--+-+++++-+++++++-++++---++++-++--+-++++++---++---+----+++-+--+-+-+--++++----+-++++-\|||| ||| || | | | || |||| ||||| | ||||| | | |||
+||| | || | ||||| ||||||| |||| |||| || | |||||| || | ||| | | | | |||| | |||| ||||| ||| || | | | || \+++--+++++--+--++++/ | | |||
+||| | || | ||||| ||||||| |||| |\++-++--+-++++++---++---+----+++-+--+-+-+--++++----+-++++-+++++-+++-++-+--+-+---++--+++--+/||| | |||| | | |||
+||| | || | ||||| ||||||| ||||/--+-++-++--+-++++++---++---+---\||| | | | | /++++----+-++++-+++++-+++-++-+\ | | || ||| | ||| | |||| | | |||
+|\+-+---++--+-+++++-+++++++-+++++--+-++-++--+-++++++---++---+---++++-+--+-+-+-+++++----+-++++-+++++-+/| || || | | || ||| | ||| | |||| | | |||
+| | | || | ||||| ||||||| |\+++--+-++-++--+-++++++---++---+---++++-+--+-+-+-+++++----+-++++-+++++-+-+-++-++-+-+--<++--+++--+-++/ | |||| | | |||
+| | | || | ||||| |||\+++-+-+++--+-+/ || | |||||| || \---++++-+--+-+-+-+++++----+-++++-+++++-+-+-++-++-+-+---++--+++--+-++---+--+/|| | | |||
+| | | \+--+-+++++-+++-+++-+-+++--+-+--++--+-++++++---++-------++++-/ | | | |||\+----+-++++-+++++-+-+-++-++-+-+---++--+++--+-++---+--+-++----+-+-+/|
+| | | | | ||||| ||| ||| \-+++--+-+--++--+-++++++---++-------++++----+-+-+-+++-+----+-++++-+++/| | | || || | | || ||| | || | | || | | | |
+| | | | | ||||| ||| ||| ||| | |/-++--+-++++++---++-------++++----+-+-+-+++-+----+-++++-+++-+-+-+-++-++-+-+---++--+++--+-++---+--+\|| | | | |
+| | | | | ||||| ||| ||| ||| | || ||/-+-++++++---++-------++++----+-+-+-+++-+\ | |||| ||| | | | || || | | || ||| | || | |||| | | | |
+| | | | |/+++++-+++-+++---+++--+\|| ||| | |||||| || /-++++----+-+-+-+++-++---+-++++-+++-+-+-+-++-++-+-+---++--+++--+-++---+--++++\ | | | |
+| | | | ||||||| ||| ||| ||| |||| ||| | |||||| || /--+-++++----+-+-+-+++-++---+-++++-+++-+-+-+-++-++-+-+>\ || ||| | || | ||||| | | | |
+| | | | ||||||| ||| ||| ||| |||| ||| | |||||| || | | |||| | \-+-+++-++---+-++++-+/| | | | || || | | | || ||| | || | ||||| | | | |
+| | | | ||||||| ||| ||| |||/-++++-+++-+-++++++---++--+--+-++++----+---+-+++-++---+-++++-+-+-+-+-+-++-++-+-+-+-++--+++--+-++---+-\||||| | | | |
+| | | | ||||||| ||| ||| \+++-++++-+++-+-++++++---++--+--+-++++----+---+-+++-++---+-++++-+-/ | | | || || | | | || ||| | || | |||||| | | | |
+| | | | ||||||| ||| ||| ||| |||| \++-+-++++++---++--+--+-++++----+---+-+++-++---+-++++-+---+-+-+-++-++-/ | | || ||| | || | |||||| | | | |
+| | | /-+--+++++++-+++-+++----+++-++++--++-+-++++++---++--+--+-++++----+---+-+++-++---+-++++-+---+-+-+-++-++---+-+\|| ||| | || | |||||| | | | |
+| | | | | ||||||| ||| ||| ||| |||| || | ||\+++---++--+--+-++++----+---+-+++-++---+-/||| | | | | || || | |||| ||| | || | |||||| | | | |
+| | | | | ||||||| ||| ||| ||| |||| || | || ||| || | | |||| | | ||| || | ||| | | | | || || | |||| ||| | || | |||||| | | | |
+| | | | | |||\+++-+++-+++----+++-++++--++-+-+/ ||| || | | ||\+----+---+-+++-++---+--+++-+---+-+-+-++-/| | |||| ||| | || | |||||| | | | |
+| | | | | ||| ||| ||| ||| ||| |||| || | | ||| || | | || | | | ||| || | ||| | | | | || | \-++++--+++--+-++---+-+++/|| | | | |
+| | | | | ||| ||| |\+-+++----+++-++++--++-+-+--+++---++--+--+-+/ | | | ||| || | ||| | | | | || | |||| ||| | || | ||| || | | | |
+| | | | | ||| ||| | | ||| ||| |||| || | | ||| || | | | | | | ||| || | ||| | | | | || | |||| ||| | || | ||| || | | | |
+| \-+--+-+--+++-+++-+-+-+++----+++-++++--++-+-+--+++---++--+--+-+--+----+---+-+++-++---+--+++-+---+-+-+-+/ | |||| ||| | || | ||| || | | | |
+| | | | ||| ||| | | ||| ||| |||| || | | ||| || | | | | | | ||| || | ||| | | | | | | |||| ||| | || | ||| || | | | |
+| | | | ||| ||| | | ||| ||| |||| || | \--+++---++--+--+-+--+----/ | ||| || | ||| | | | | | | ||\+--+++--+-++---+-+++-++---/ | | |
+\---+--+-+--+++-+++-+-+-+++----+++-++++--++-+----+++---++--+--+-+--+--------/ ||| || | ||| | | | | | | || | ||| | || | ||| || | | |
+ | | | ||| ||| | | ||| ||| |||| || | ||| || | \-+--+----------+++-++---+--+++-+---+-+-+-+---+-----++-+--+++--+-++---+-+++-+/ | | |
+ | | | ||| ||| | | \++----+++-++++--++-+----+++---++--+----+--+----------+++-++---/ ||| | | | | | | || | ||| | || | |\+-+------/ | |
+ | | | ||| ||| | | || ||| |||| || | ||| || | |/-+----------+++-++--\ ||| | | | | | | || | ||| | || | | | | | |
+ | | | ||| ||| | | || ||| |||| || | ||| || | || | ||| || | ||| | /+-+-+-+---+-----++-+--+++--+-++---+-+-+\| | |
+ | | | ||| ||| | | || ||| |||| || | ||| || | || \----------+++-++--+---+++-+--++-+-+-+---+-----++-+--+++--/ || | | ||| | |
+ | | | ||| ||| | | \+----+++-++++--++-+----+++---++--+----++------------+++-++--+---+++-+--+/ | | | | || | ||| || | | ||| | |
+ | | | |\+-+++-+-+---+----+++-+/|| || | ||| || | || ||| || | \++-+--+--+-+-+---+-----++-+--+++----+/ | | ||| | |
+ | | | | | ||| \-+---+----+++-+-++--++-+----/|| || | || ||| || | || | | | | | | || | ||| | | | ||| | |
+ | | | | \-+++---+---+----+++-+-++--++-+-----+/ || | || \++-++--+----++-+--+--+-+-+---/ || | |\+----+----+-+-+++--------/ |
+ | | | | ||| | v ||| \-++--++-+-----+----++--+----++-------------++-++--+----++-+--+--+-+-/ || | | | | | | ||| |
+ | | | | ||| | | |\+---++--++-+-----+----++--+----/| || || /+----++-+--+--+-+-----------++-+--+-+----+---\| | ||| |
+ | \-+--+---+++---+---+----+-+---++--++-+-----+----++--+-----+-------------++-++-++----++-+--+--+-+-----------+/ | | | | || | ||| |
+ | | | ||| | | | | || || | | |\--+-----+-------------/| || || || | | | | | | | | | || | ||| |
+ | | | ||| | | | | || || \-----+----+---+-----+--------------+-++-++----++-+--+--+-+-----------+--+--+-+----/ || | ||| |
+ | | | ||| | | | | || || | | | \--------------+-++-+/ \+-+--+--+-+-----------+--+--+-/ || | ||| |
+ | | | ||| | | | | || \+-------+----/ | | || | | | | | \-----------+--+--+----------++-+-+++----------/
+ | | | |\+---+---+----+-+---++---+-------+--------+--------------------+-++-+------+-+--+--+-------------+--/ | || | |||
+ | \--+---+-+---+---+----+-+---++---+-------+--------+--------------------/ || | | | | | | | || | |||
+ | | | | | | | | || | | \----------------------++-+------+-+--+--+-------------/ | || | |||
+ | | | | | | | | || | | || \------+-+--+--+-------------------+----------/| | |||
+ | | | | | | | \---++---+-------+-------------------------------++--------+-+--+--+-------------------+-----------+-/ |||
+ | | | | | | | || | | || \-+--+--+-------------------+-----------+---++/
+ | \---+-+---/ | | || | | \+----------+--+--+-------------------+-----------/ ||
+ \-----------+<+-------+----+-----++---+-------+--------------------------------+----------/ | | | ||
+ \-+-------+----+-----++---+-------+--------------------------------+-------------+--/ | ||
+ | \----+-----/\---+-------+--------------------------------+-------------+----------------------+---------------/|
+ \------------/ | \--------------------------------+-------------+----------------------/ |
+ \----------------------------------------/ \---------------------------------------/
diff --git a/src/13/part1 b/src/13/part1
new file mode 100644
index 0000000..22fe267
--- /dev/null
+++ b/src/13/part1
@@ -0,0 +1,188 @@
+--- Day 13: Mine Cart Madness ---
+
+A crop of this size requires significant logistics to transport produce, soil, fertilizer, and so
+on. The Elves are very busy pushing things around in carts on some kind of rudimentary system of
+tracks they've come up with.
+
+Seeing as how cart-and-track systems don't appear in recorded history for another 1000 years, the
+Elves seem to be making this up as they go along. They haven't even figured out how to avoid
+collisions yet.
+
+You map out the tracks (your puzzle input) and see where you can help.
+
+Tracks consist of straight paths (| and -), curves (/ and \), and intersections (+). Curves connect
+exactly two perpendicular pieces of track; for example, this is a closed loop:
+
+/----\
+| |
+| |
+\----/
+
+Intersections occur when two perpendicular paths cross. At an intersection, a cart is capable of
+turning left, turning right, or continuing straight. Here are two loops connected by two
+intersections:
+
+/-----\
+| |
+| /--+--\
+| | | |
+\--+--/ |
+ | |
+ \-----/
+
+Several carts are also on the tracks. Carts always face either up (^), down (v), left (<), or right
+(>). (On your initial map, the track under each cart is a straight path matching the direction the
+cart is facing.)
+
+Each time a cart has the option to turn (by arriving at any intersection), it turns
+left the first time, goes straight the second time, turns right the third time, and then repeats
+those directions starting again with left the fourth time, straight the fifth time, and so on. This
+process is independent of the particular intersection at which the cart has arrived - that is, the
+cart has no per-intersection memory.
+
+Carts all move at the same speed; they take turns moving a single step at a time. They do this based
+on their current location: carts on the top row move first (acting from left to right), then carts
+on the second row move (again from left to right), then carts on the third row, and so on. Once
+each cart has moved one step, the process repeats; each of these loops is called a
+tick.
+
+For example, suppose there are two carts on a straight track:
+
+| | | | |
+v | | | |
+| v v | |
+| | | v X
+| | ^ ^ |
+^ ^ | | |
+| | | | |
+
+First, the top cart moves. It is facing down (v), so it moves down one square. Second, the bottom
+cart moves. It is facing up (^), so it moves up one square. Because all carts have moved, the first
+tick ends. Then, the process repeats, starting with the first cart. The first cart moves down,
+then the second cart moves up - right into the first cart, colliding with it! (The location of the
+crash is marked with an X.) This ends the second and last tick.
+Here is a longer example:
+
+/->-\
+| | /----\
+| /-+--+-\ |
+| | | | v |
+\-+-/ \-+--/
+ \------/
+
+/-->\
+| | /----\
+| /-+--+-\ |
+| | | | | |
+\-+-/ \->--/
+ \------/
+
+/---v
+| | /----\
+| /-+--+-\ |
+| | | | | |
+\-+-/ \-+>-/
+ \------/
+
+/---\
+| v /----\
+| /-+--+-\ |
+| | | | | |
+\-+-/ \-+->/
+ \------/
+
+/---\
+| | /----\
+| /->--+-\ |
+| | | | | |
+\-+-/ \-+--^
+ \------/
+
+/---\
+| | /----\
+| /-+>-+-\ |
+| | | | | ^
+\-+-/ \-+--/
+ \------/
+
+/---\
+| | /----\
+| /-+->+-\ ^
+| | | | | |
+\-+-/ \-+--/
+ \------/
+
+/---\
+| | /----<
+| /-+-->-\ |
+| | | | | |
+\-+-/ \-+--/
+ \------/
+
+/---\
+| | /---<\
+| /-+--+>\ |
+| | | | | |
+\-+-/ \-+--/
+ \------/
+
+/---\
+| | /--<-\
+| /-+--+-v |
+| | | | | |
+\-+-/ \-+--/
+ \------/
+
+/---\
+| | /-<--\
+| /-+--+-\ |
+| | | | v |
+\-+-/ \-+--/
+ \------/
+
+/---\
+| | /<---\
+| /-+--+-\ |
+| | | | | |
+\-+-/ \-<--/
+ \------/
+
+/---\
+| | v----\
+| /-+--+-\ |
+| | | | | |
+\-+-/ \<+--/
+ \------/
+
+/---\
+| | /----\
+| /-+--v-\ |
+| | | | | |
+\-+-/ ^-+--/
+ \------/
+
+/---\
+| | /----\
+| /-+--+-\ |
+| | | X | |
+\-+-/ \-+--/
+ \------/
+
+After following their respective paths for a while, the carts eventually crash. To help prevent
+crashes, you'd like to know the location of the first crash. Locations are given in X,Y coordinates,
+where the furthest left column is X=0 and the furthest top row is Y=0:
+
+ 111
+ 0123456789012
+0/---\
+1| | /----\
+2| /-+--+-\ |
+3| | | X | |
+4\-+-/ \-+--/
+5 \------/
+
+In this example, the location of the first crash is 7,3.
+
+
+
+
diff --git a/src/13/part2 b/src/13/part2
new file mode 100644
index 0000000..e7ccee4
--- /dev/null
+++ b/src/13/part2
@@ -0,0 +1,26 @@
+--- Part Two ---
+
+The game didn't run because you didn't put in any quarters. Unfortunately, you did not bring any
+quarters. Memory address 0 represents the number of quarters that have been inserted; set it to 2 to
+play for free.
+
+The arcade cabinet has a joystick that can move left and right. The software reads the position of
+the joystick with input instructions:
+
+
+ - If the joystick is in the neutral position, provide 0.
+
+ - If the joystick is tilted to the left, provide -1.
+
+ - If the joystick is tilted to the right, provide 1.
+
+
+The arcade cabinet also has a segment display capable of showing a single number that represents the
+player's current score. When three output instructions specify X=-1, Y=0, the third output
+instruction is not a tile; the value instead specifies the new score to show in the segment display.
+ For example, a sequence of output values like -1,0,12345 would show 12345 as the player's current
+score.
+
+Beat the game by breaking all the blocks. What is your score after the last block is broken?
+
+
diff --git a/src/13/solve.py b/src/13/solve.py
new file mode 100644
index 0000000..e89466c
--- /dev/null
+++ b/src/13/solve.py
@@ -0,0 +1,148 @@
+import sys
+sys.path.append("../common")
+import aoc
+
+tmap = [list(l) for l in aoc.data.split("\n") if len(l) != 0]
+xlen, ylen = len(tmap[0]), len(tmap)
+
+arrows = dict()
+arrows["<"] = (-1, 0)
+arrows[">"] = (1, 0)
+arrows["^"] = (0, -1)
+arrows["v"] = (0, 1)
+
+directions = [(-1,0), (0,-1), (1, 0), (0, 1)] # l - u - r - d
+
+def check_pos(x, y):
+ if x < xlen and x >= 0 and y < ylen and y >= 0:
+ return tmap[y][x]
+ return " "
+
+def correct(x, y):
+ cr = check_pos(x+1, y)
+ cl = check_pos(x-1, y)
+ cu = check_pos(x, y-1)
+ cd = check_pos(x, y+1)
+
+ if cr == "|": cr = " "
+ if cl == "|": cl = " "
+ if cu == "-": cu = " "
+ if cd == "-": cd = " "
+
+ r = cr != " "
+ l = cl != " "
+ u = cu != " "
+ d = cd != " "
+
+ vsum = r + l + u + d
+ if vsum > 2:
+ return "+"
+
+ # 2 around
+ if r:
+ if l:
+ return "-"
+ elif u:
+ return "/"
+ else:
+ return "\\"
+ else:
+ if not l:
+ return "|"
+ elif u:
+ return "/"
+ else:
+ return "\\"
+
+carts = list()
+for y in range(ylen):
+ for x in range(xlen):
+ if tmap[y][x] in arrows:
+ carts.append([x, y, arrows[tmap[y][x]], 0, 0])
+ tmap[y][x] = correct(x,y)
+
+def cart_at(x, y):
+ global carts
+ for i in range(len(carts)):
+ c = carts[i]
+ if c[0] == x and c[1] == y and not c[4]:
+ return i
+ return None
+
+def draw_map():
+ for y in range(ylen):
+ f = lambda x : "".join(["#" if cart_at(x,y) != None else tmap[y][x]])
+ aoc.debug([f(x) for x in range(len(tmap[y]))])
+
+def advance(cart):
+ ncart = [0 for x in range(5)]
+ ncart[0] = cart[0]+cart[2][0]
+ ncart[1] = cart[1]+cart[2][1]
+ col = cart_at(ncart[0], ncart[1])
+ if col != None:
+ return ncart[0], ncart[1], col
+
+ c = tmap[ncart[1]][ncart[0]]
+ d = directions.index(cart[2])
+
+ if c == "+":
+ d = (d + len(directions)-1 + cart[3]) % len(directions)
+ ncart[2] = directions[d]
+ ncart[3] = (cart[3] + 1) % 3
+ else: # dont need to change direction for '-' and '|'
+ if c == "/":
+ ncart[2] = directions[3-d]
+ elif c == "\\":
+ if d == 0: #l
+ ncart[2] = directions[1]
+ elif d == 1: #u
+ ncart[2] = directions[0]
+ elif d == 2: #r
+ ncart[2] = directions[3]
+ elif d == 3: #d
+ ncart[2] = directions[2]
+ else:
+ ncart[2] = cart[2]
+ ncart[3] = cart[3]
+ return ncart
+
+
+def solve1(args):
+ global carts
+
+ crash = None
+ while not crash:
+ carts = sorted(carts, key=lambda x:(x[0], x[1]))
+ for c in range(len(carts)):
+ nc = advance(carts[c])
+ if len(nc) == 3:
+ crash = nc
+ break
+ else:
+ carts[c] = nc
+
+ return f"{crash[0]},{crash[1]}"
+
+def solve2(args):
+ global carts
+
+ while len(carts) > 1:
+ carts = sorted(carts, key=lambda x:(x[0], x[1]))
+ rcarts = list()
+ for c in range(len(carts)):
+ if carts[c][4]: continue;
+ nc = advance(carts[c])
+ if len(nc) == 3:
+ carts[c][4] = 1
+ carts[nc[2]][4] = 1
+ rcarts.append(carts[c])
+ rcarts.append(carts[nc[2]])
+ else:
+ carts[c] = nc
+ for c in rcarts:
+ if c in carts: # prevent doubles
+ carts.remove(c)
+
+ return f"{carts[0][0]},{carts[0][1]}"
+
+aoc.run(solve1, solve2)
diff --git a/src/13/test1 b/src/13/test1
new file mode 100644
index 0000000..30bc010
--- /dev/null
+++ b/src/13/test1
@@ -0,0 +1,7 @@
+/>-<\
+| |
+| /<+-\
+| | | v
+\>+</ |
+ | ^
+ \<->/