mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 20:53:30 +02:00
2018 day 13 - oop-ish solution to carts moving on tracks and colliding
This commit is contained in:
Executable
+150
@@ -0,0 +1,150 @@
|
|||||||
|
/-----------------\ /--------------------------------------------------------------------------------\
|
||||||
|
/----+----------\ | /----------------+-------------------------------------------------------------------\ |
|
||||||
|
| | /-----+---\ | | /--------------+->-----------------------------------------------------------\ | |
|
||||||
|
/+----+----+-----+---+--+--+-+--------------+-----------------------\ /----<-------------------\ | | |
|
||||||
|
/------------------++----+----+-----+---+--+--+-+------------\ | /----------------+-------+------------------------+----+-----+--\ |
|
||||||
|
| || | | | | | | | | |/-----+----------------+-------+--------------\ | | | | |
|
||||||
|
| || | | | | | | | | || v /---------+-------+--------------+---------+----+-----+--+--\ |
|
||||||
|
| || | | | /+--+--+-+--------\ | || | | | /-----+-------\ /---+---------+----+-----+-\| | |
|
||||||
|
| /--++----+----+-----+--++--+--+-+--------+---+-++-----+------+---------+-+---\ | | | | | | | || | |
|
||||||
|
| /--------+--++----+----+-----+--++--+--+-+--------+---+-++-----+-----\| /+-+---+-+-------+--+---+---------+----+-----+-++--+------+\
|
||||||
|
| | /------+--++----+----+-----+--++--+--+-+--------+---+-++----<+-----++--------++-+---+-+-\ | | | | | | || | ||
|
||||||
|
| | | | || | | | || | /+-+--------+---+-++-----+-----++--------++-+---+-+-+-----+--+---+---------+----+-----+-++--+----\ ||
|
||||||
|
| /--+-+------+--++----+----+-----+--++-\| || | | | || | || || | | | | | | | | | | || | | ||
|
||||||
|
| | | | | || | | | || || || | | | || | /-++--------++-+---+-+-+-----+--+---+-\ |/---+-----+\|| | | ||
|
||||||
|
| | | | /+--++----+----+-----+--++-++-++-+-------\| | ||/----+---+-++--------++-+---+-+-+-----+--+---+-+-------++---+-----++++--+\ | ||
|
||||||
|
|/--+--+-+-----++--++----+----+-----+--++-++-++-+-------++---+-+++----+---+\|| || | | | | | | | | || | |||| || | ||
|
||||||
|
|| | | | || || | \-----+--+/ || || | || | ||| | |||| || | | | | | | | | || | |||| || | ||
|
||||||
|
|| | | |/----++--++----+----------+--+--++-++-+-------++---+-+++----+---++++--------++-+->-+-+-+-----+--+---+-+-----\ || | |||| || | ||
|
||||||
|
|| | | || || || | | | || |\-+-------++---+-+++----+---++++--------++-+---+-+-+-----+--+---+-+-----+-++---+-----/||| || | ||
|
||||||
|
/++--+--+-++--\ || || | | | || | | || | ||| | |||| || | | | | | | | | | || | ||| || | ||
|
||||||
|
||| | | || | || || | | \--++-+--+-------+/ | ||| | |||| || | | | | | | | | | || | ||| || | ||
|
||||||
|
||| | | || | || || | | || | | | | ||| | |||| /------++-+---+-+-+-----+--+---+-+-----+-++---+-----\||| || | ||
|
||||||
|
||| | | || | || || | | || | | | | ||| | |||| |/-----++-+---+-+-+-----+--+---+-+-----+-++---+-\ |||| || | ||
|
||||||
|
||| | | || | || || /--+----------+-----++-+--+-------+----+-+++----+---++++\|| || | | | | | | | | | || | | |||| || | ||
|
||||||
|
||| | | || | || || | | | || | | | | ||| | |||\+++-----++-+---+-+-+-----+--+---+-+-----+-++---+-+---++++--/| | ||
|
||||||
|
||| | | || | || || | | | || | /+---->--+---\| ||| | ||| ||| /++-+---+-+-+-----+--+---+-+-----+-++---+-+\ |||| | | ||
|
||||||
|
||| | |/++--+-++--++-+--+----------+-----++-+-++-------+---++-+++----+---+++-+++----+++-+---+-+-+-----+--+---+-+---\ | || | || |||| | | ||
|
||||||
|
||| | |||| | || || | | /-----+-----++-+-++-------+---++-+++----+---+++-+++----+++-+---+-+-+-----+--+-\ | | | | || | || |||| | | ||
|
||||||
|
||| | |||| | || || | | | | || | || | || |\+----+---+++-+++----+++-+---+-+-+-----+--+-+-/ | |/+-++---+-++--++++---+---+-++\
|
||||||
|
||| | ||\+--+-++--++-+--+----+-----+-----++-+-++-------+---++-+-+----+---+++-+++----+++-+---+-+-/ | | | | ||| || | || |||| | | |||
|
||||||
|
/+++--+--++-+--+-++--++-+--+----+-----+-----++-+-++-------+---++-+-+----+---+++-+++----+++-+--\| | | | | | ||| || | || |||| | | |||
|
||||||
|
|||| | || | | || || | | | | || | || | || | | | ||| ||| ||| \--++-+-------/ | | | ||| || | || |||| | | |||
|
||||||
|
|||| | /++-+--+-++--++-+--+----+-----+-\ || | || /---+---++-+-+----+---+++-+++----+++----++-+----------+-+---+---+++-++---+\|| |||| | | |||
|
||||||
|
|||| /+-+++-+--+-++--++-+--+----+-----+-+---++-+-++---+---+---++-+-+----+---+++-+++----+++----++-+---\ | | | ||| || |||| |||| | | |||
|
||||||
|
|||| || ||| | | || || | | /-+-----+-+---++-+-++---+---+---++-+-+--\ | ||| ||| |\+----++-+---+------+-+---+---+++-++---++++--++++---+---+-+/|
|
||||||
|
|||| || ||| | v || |\-+--+--+-+-----/ | || | || | /-+---++-+-+--+-+---+++-+++-\ | | || | | | | | ||| || |||| |||| | | | |
|
||||||
|
|||| || ||| | |/++--+--+--+--+-+-------+---++-+-++---+-+-+---++-+-+--+-+---+++-+++-+--+-+----++-+---+------+-+-\ | ||| || |||| |||| | | | |
|
||||||
|
|||| || ||| | |||| | | | | | | || | || | | | || | | | | ||| |\+-+--+-+----++-+---+------+-+-+-+---+++-++---++++--/||| | | | |
|
||||||
|
|||| || |||/+--++++--+--+--+--+-+-------+---++-+-++---+-+-+---++-+-+--+-+---+++-+-+-+--+-+----++-+---+------+-+-+-+-\ ||| || |||| ||| | | | |
|
||||||
|
|||| || ||||| |||| | /+--+--+-+-----\ | || | || | | | || | | | | ||| | | | \-+----++-+---+------+-+-+-+-+-+++-++---+++/ ||| | | | |
|
||||||
|
|||| || ||||| |||| | || | | | |/+---++-+-++---+-+-+---++-+-+--+-+---+++-+-+-+----+----++-+---+------+\| | | | ||| || ||| ||| | | | |
|
||||||
|
|||| || ||||| |||| |/++--+--+-+-----+++---++-+-++---+-+-+---++-+-+--+-+---+++-+-+-+---\| || | | ||| | | | ||| || ||| ||| | | | |
|
||||||
|
|||| || ||||| |||| |||| | | | ||| || | ||/--+-+-+---++-+-+--+-+---+++-+-+-+---++----++-+---+------+++-+-+-+-+++-++---+++----+++---+--\| | |
|
||||||
|
||||/++-+++++--++++--++++--+--+-+-----+++---++-+-+++--+-+-+---++-+-+--+-+---+++-+-+-+---++\ || | | ||| | | | ||| || ||| ||| | || | |
|
||||||
|
||||||| ||||| |||\--++++--+--+-+-----+++---++-+-+++--+-+-+---++-+-+--+-+---+++-+-+-+---+++---+/ | | ||| | | | ||| || ||| ||| | || | |
|
||||||
|
||||||| ||||| ||| /-++++--+--+-+-----+++---++-+-+++-\| | | || | | | | |||/+-+-+---+++---+--+---+------+++-+-+-+-+++-++---+++----+++-\ | || | |
|
||||||
|
||||||| ||||| ||| | ||||/-+--+-+-----+++---++-+-+++-++-+-+---++-+-+--+-+---+++++-+-+---+++---+--+---+------+++-+-+-+-+++-++-\ ||| ||| | | || | |
|
||||||
|
\++++++-+++++--+++-+-+++++-+--+-+-----+++---++-+-+++-++-+-+---++-+-+--+-+---+++++-+-+---+++---/ | | ||| | | | ||| || | ||| ||| | | || ^ |
|
||||||
|
|||||| ||||| ||| | ||||| | | | ||| || | ||| || | | || | |/-+-+---+++++-+-+---+++------+---+------+++-+-+-+-+++-++-+-+++----+++-+-+--++\| |
|
||||||
|
|||||| ||||| ||| | ||||| | | | ||| || | ||| || | |/--++-+-++-+-+---+++++-+-+---+++------+-\ | \++-+-+-+-+++-++-+-+++----+/| | | |||| |
|
||||||
|
|||||| ||||| ||| | ||||| | | | ||| || | ||| || | || || | || | | ||||| | |/--+++------+-+-+-------++-+-+-+-+++-++-+-+++-\ | | | | |||| |
|
||||||
|
||\+++-+++++--+++-+-+++++-+--+-+-----+++---++-+-+++-++-+-++--++-+-++-+-+---+/||| | || ||| | | | || | | | ||| ||/+-+++-+--+-+-+-+--++++\|
|
||||||
|
|| ||| ||||| ||| | ||||| | | | ||| || | ||| || | ||/-++-+-++-+-+\ | ||| | ^| ||| | | | /-----++-+-+-+-+++-++++-+++-+--+-+-+-+-\||||||
|
||||||
|
|| |||/+++++--+++-+-+++++-+--+-+-----+++---++-+-+++-++-+-+++-++-+-++-+-++--+-+++-+-++--+++------+-+-+\| || | | | ||| |||| ||| | | | | | |||||||
|
||||||
|
|| ||||||||| ||| | ||||| | | | ||| || | ||| || | ||| || \-++-+-++--+-+++-+-++--+++------+-+-+++-----++-+-+-+-+++-++++-+++-+--+-+-+-+-++++/||
|
||||||
|
/-++-+++++++++--+++-+-+++++-+--+-+-----+++---++-+-+++-++-+-+++-++---++-+-++--+-+++-+-++--+++------+\| ||| /--++-+-+-+-+++\|||| ||| | | | | | |||| ||
|
||||||
|
| || ||||||||| ||| | ||||| | | | ||| || | |||/++-+-+++-++---++-+-++--+-+++-+-++--+++------+++-+++--+-\|| | | | |||||||| ||| | | | | | |||| ||
|
||||||
|
| || ||||||||| ||| | ||||| | | | ||| ||/+-++++++-+-+++-++---++-+-++--+-+++\| || ||| ||| ||| | ||| | | | |||||||| ||| | | | | | |||| ||
|
||||||
|
| ||/+++++++++--+++-+\||||| \--+-+-----+++---+/|| \+++++-+-+++-/| || | || | ||||| || ||| ||| ||| | ||| | | | |||||||| ||| | | | | | |||| ||
|
||||||
|
| |||||||||||| ||| ||||||| /--+-+-----+++---+-++--+++++-+\||| | |^ | || | ||||| || ||| ||| ||| | ||| | | | |||||||| ||| | | | | | |||| ||
|
||||||
|
| |||||||||||| ||| ||||||| | | | ||| | || ||||| ||||| |/--++-+-++--+<+++++-++--+++------+++-+++--+-+++-+-+-+-++++++++-+++-+\ | | | | |||| ||
|
||||||
|
| |||||||||||| ||| ||||||| | | | ||| /+-++--+++++-+++++--++--++-+-++--+-+++++-++--+++------+++-+++-\| ||| | | | |||||||| ||| || | | | | |||| ||
|
||||||
|
| |||||||||||| ||| ||||||| | | | ||| || ||/-+++++-+++++--++--++-+-++--+-+++++-++-\||| ||| ||| || ||| | | | |||||||| ||| || | | | | |||| ||
|
||||||
|
| |||||||||||| |\+-+++++++-+--+-+-----+++--++-+++-+++++-+++++--++--++-+-++--+-+++++-++-++++------+++-+++-++-+++-/ | | |||||||| ||| || | | | | |||| ||
|
||||||
|
| |||||||||||\--+-+-+++++++-+--+-+-----+++--++-+++-+++++-+++++--++--++-+-++--+-+++++-++-++++------+++-+++-++-+++---+-+-++/||||| ||| || | | | | |||| ||
|
||||||
|
| ||||||||||| | | ||\++++-+--+-+-----+++--++-+++-+++++-+++++--++--++-+-++--+-+++++-++-++/| ||| ||| || ||| | | || ||||| ||| || | | | | |||| ||
|
||||||
|
| ||||||||||| | | || |||| | | | /-+++--++-+++-+++++-+++++--++--++-+-++--+-+++++-++-++-+------+++-+++-++-+++---+-+-++-+++++-+++-++-+\| | | |||| ||
|
||||||
|
| ||||||||||| | | || |||| | | | | ||| || ||| |\+++-+++++--++--++-+-++--+-+++++-++-++-+------+++-+++-++-+++---+-+-++-+++++-+++-++-+++-+-+-+/|| ||
|
||||||
|
| ||||||||||| /+-+-++-++++-+--+-+---+-+++--++-+++-+-+++-+++++--++--++-+-++--+-+++++-++-++-+--\ ||| ||| || ||| |/+-++-+++++-+++-++-+++-+-+-+\|| ||
|
||||||
|
| ||||||||||| || | || |||| | | | | ||| || ||| | ||| ||||| || || | || | ||||| || || | | ||| ||| || ||| ||| || ||||| ||| || ||| | | |||| ||
|
||||||
|
| ||||||||||| || | || |||| | | | | ||| || ||| | ||| ||||| || || | || | |\+++-++-++-+--+---+++-+++-++-+++---+++-++-+++++-+++-++-+++-/ | |||| ||
|
||||||
|
| ||||||||||| || |/++-++++-+--+-+---+-+++--++-+++-+-+++-+++++--++-\|| | || | | ||| || || | | \++-+++-++-+++---+++-++-+/||| ||| || ||| | |||| ||
|
||||||
|
| ||||||||||| || |||| |||| | \-+---+-+++--++-+++-+-+++-+++++--++-+++-/ || | | ||| || ||/+--+----++-+++-++-+++---+++-++-+-+++-+++-++-+++--\| |||| ||
|
||||||
|
| ||||||||||| || |||| |||| | | | ||| /++-+++-+-+++-+++++--++-+++---++--+-+-+++-++-++++--+----++-+++-++-+++---+++-++-+-+++-+++-++-+++--++\|||| ||
|
||||||
|
| ||||||||||| || |||| ||||/+----+---+-+++-+++-+++-+-+++-+++++--++-+++---++--+-+-+++-++-++++--+----++-+++\|| ||| ||| || | ||| ||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| |\++++----+---+-/|| ||| ||| | ||| ||||| || ||| || | | ||| || |||| | || |||||| ||| ||| || | ||| ||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| | |||| | | || ||| ||| | ||| ||||| /++-+++---++--+-+-+++-++\|||| | || |||||| ||| ||| || | ||| ||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| | \+++----+---+--++-+++-+++-+-+++-+++++-+++-+++---++--+-+-/|| ||||||| | ||/++++++-+++\ ||| || | ||| ||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| | ||| | | || ||| ||| | ||| ||||| ||| ||| || | | || ||||||| | ||||||||| |||| ||| || | ||| ||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| | ||| | | || ||| ||| | ||| ||||| ||| ||| || | | || |||||||/-+----+++++++++-++++--+++-++-+-+++\||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| | ||| | | || ||| ||| | ||| ||||| ||| ||| || | | || |||||||| | ||||||||| |||| ||| || | ||||||| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || |||| | ||| | | || ||| ||| \-+++-+++++-+++-+++---++--+-+--++-++++++++-+----+++++++++-++++--+++-++-+-++++/|| || ||| ||||||| ||
|
||||||
|
| ||||||||||| || \+++-+--+++----+---+--++-+++-+++---+++-++/|| ||| ||| ||/-+-+--++\|||||||| | |||||||||/++++--+++-++-+-++++-++-++-+++-\||||||| ||
|
||||||
|
| ||||||||||| || |||/+--+++----+---+--++-+++-+++---+++-++-++-+++\||| ||| | | ||||||||||| | |||||||||||||| ||| || | |||| || || ||| |||||||| ||
|
||||||
|
| ||||^|||||| || ||||| ||| | | || ||| ||| ||| || || ||||||| ||| | | ||||||||||| | |||||||||||||| |\+-++-+-++++-++-++-+++-+++++/|| ||
|
||||||
|
| |\+++++++++--++--+++++--+++----+---+--++-+++-+++---+++-++-++-+/|||\+---+++-+-+--+++++++++++-+----++++++++++++++--+-+-++-+-++++-++-++-+++-++/|| || ||
|
||||||
|
| | ||||||||| || ||||| ||| | | || ||| ||| ||| || || | ||| | ||| | | ||||||||||| | /-++++++++++++++-\| | || | |||| || || ||| || || || ||
|
||||||
|
| | ||||||\++--++--+++++--+++----+---+--++-+++-+++---+++-++-++-+-+++-+---+++-+-/ ||||||||||| | | |||||||||||||| || | || | |||| || || ||| || || || ||
|
||||||
|
|/+-++++++-++-\|| ||||| ||\----+---+--++-+++-+++---+++-+/ || | ||| | ||| | ||||||||||| | | |||||||||||||| || | || | |||| || || ||| || || || ||
|
||||||
|
||| |||||| || ||| ||||| || | | || ||| ||| ||| |/-++-+-+++-+\ ||| | ||||||||||| | | |||||||||||||| || | || | |||| || || ||| || || || ||
|
||||||
|
||| |||||| || ||| ||||| || | | || ||| ||| ||| || |\-+-+++-++--+/| | ||||||||||\-+--+-++++++++++++++-++-+-++-+-+++/ || || ||| || || || ||
|
||||||
|
||| |||||| || ||| ||||| || | | || ||| ||| ||| || | | ||| || | | | |||||||||| | | ||\++++++++++/ || |/++-+-+++--++-++\||| || || || ||
|
||||||
|
||| |||||| || ||| ||||| || | | || ||| ||| ||| || | | ||| || | | | |||||||||| | | || |||||||||| || |||| | ||| || |||||| || || || ||
|
||||||
|
||| |||||| || ||| /+++++--++-----+---+--++-+++-+++---+++-++-+--+-+++-++--+-+-+----++++++++++--+--+-++\|||||||||| || |||| | ||| || |||||| || || || ||
|
||||||
|
||| |||||| || ||| ||||||/-++-----+---+--++-+++-+++---+++-++-+--+-+++-++--+-+-+----++++++++++--+--+-+++++++++++++--++-++++-+-+++-\|| |||||| || || || ||
|
||||||
|
||| |||||| || ||| ||||||| || | | || ||| ||| ||| || | | ||| || | | | |||||||||| | | ||||||||||||| || |||| | ||| ||| |||||| || || || ||
|
||||||
|
||| |||||| || ||| ||||v|| || | | || ||| ||| ||| || | | ||| || | | | |||||||||| | | ||||||||||||| || |||| | ||| ||| |||||| || || || ||
|
||||||
|
||| |||||| || |||/+++++++-++----\| | || ||| ||| ||| || | \-+++-++--+-+-+----+++++/|||| | | ||||||||||||| || |||| | ||| ||| |||||| || || || ||
|
||||||
|
||| |||||| || ||||||||||| || || | || ||| |\+---+++-++-+----+++-++--+-+-+----+++++-++++--+--+-+++++++++++++--++-++++-+-+++-+++-++++++-++-++-/| ||
|
||||||
|
||| |||||| || ||||||||||| || || | || ||| | | ||| |\-+----+++-+/ | | | ||||| |||| | | ||||||||||||| /++-++++-+-+++-+++-++++++-++-++--+\||
|
||||||
|
||| |||||| || ||||||||||| || || | || ||| | | ||| | | /+++-+---+-+-+--\ ||||| |||| | | ||||||||||||| ||| |||| | ||| ||| |||||| || || ||||
|
||||||
|
||| |||||| || ||||||||||| || || | || ||| | | ||\-+--+---++++-+---+-+-+--+-+++++-++++--+--+-+++++++++++++-+++-++++-+-+++-+/| |||||| || || ||||
|
||||||
|
\++-++++++-++-+++++++++++-++----++---+--++-+++-+-+---++--+--+---++++-+---+-+-+--+-+++++-++++--+--+-/|||||||||||| ||| |||| | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| || ||||||||||| || || | || ||| | | || | | |||| | | | \--+-+++++-++++--+--+--++++++++++++-++/ |||| | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| || |||||||||\+-++----++---+--++-+++-+-+---++--+--+---++++-+---+-+----+-+++++-+/|| | | |||||||||||| || |||| | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| || ||||||||| | || || | || ||| | | \+--+--+---++++-+---+-+----+-+++++-+-++--+--+--+++++++++/|| || |||| | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| || ||||||||| | || /-++---+--++-+++-+-+----+--+--+---++++-+---+-+----+-+++++-+-++--+--+--+++++++++-++-++-\|||| | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| \+-+++++++++-+-++--+-++---+--++-+++-+-+----+--+--+---++++-+---+-+----+-+++++-+-++--+--+--+++++++++-++-++-+++/| | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| | ||||\++++-+-++--+-++---+--++-+++-+-+----+--+--+---++++-+---+-+----+-+++++-+-++--+--+--+/||||||| || || ||| | | ||| | | |||||| || || ||||
|
||||||
|
|| |||||| | |||| |||| | || | || | || ||| | | | | | |||| | \-+----+-+++++-+-++--+--+--+-+++++++-++-++-+++-+-+-+++-+-+-+++++/ || || ||||
|
||||||
|
|| |||||| | |||| |||| | || | || | \+-+++-+-+----+--+--+---++++-+-----+----+-+++++-+-++--+--+--+-+++++++-/| || ||\-+-+-+++-+-+-++/|| || || ||||
|
||||||
|
|| ||||||/-+-++++-++++-+-++--+-++---+---+-+++-+-+----+\ | | |||v | | | ||||| | || | | | ||||||| | || || | | ||| | | || || || || ||||
|
||||||
|
|| |||\+++-+-++++-++++-+-++--+-++---+---+-++/ | | || | | |||| | | /-+-+++++-+-++--+--+--+-+++++++--+-++-++--+-+-+++-+-+-++-++--++-++\ ||||
|
||||||
|
|| ||| ||| | |||| |||| | || | || | | || | | || | /+---++++-+----\| | | |\+++-+-++--+--+--+-+++++++--+-++-++--+-+-+++-+-/ || || || ||| ||||
|
||||||
|
|| ||| |\+-+-++++-++++-+-++--+-++---+---/ || | | || | |\---++++-+----++--+-+-+-+++-+-++--+--+--/ ||||||| | || || | | ||| | || || || ||| ||||
|
||||||
|
|| ||| | | | |||| |||| | || /+-++---+-----++--+-+----++-+-+----++++-+----++--+-+-+-+++-+-++--+--+----+++++++--+-++-++-\| | ||| | || || || ||| ||||
|
||||||
|
|| |\+-+-+-+-++++-++++-+-++-++-++---+-----++--+-+----++-+-+----++++-+----++--+-+-+-+++-+-+/ | \----+++++++--+-+/ || || | ||| | || || || ||| ||||
|
||||||
|
|| | | | | | |||| |||| | || || || | || | | || | | |||| | || | | | ||| | | | ||\++++--+-+--++-++-+-+++-+---++-++--++-+/| ||||
|
||||||
|
|| | | | | | |||| |||| | || || ||/--+-----++--+\| || | | |||| | || | | | ||| | | | /++-++++--+-+-\|| || | ||| | || || || | | ||||
|
||||||
|
|\-+-+-+-+-+-++/| |||\-+-++-++-+++--+-----++--+++----++-+-+----++/| | || | | | ||| | | | ||| |||| | | ||| || | ||| | || || || | | ||||
|
||||||
|
| | \-+-+-+-++-+-+++--+-++-++-+++--+-----++--+++----++-+-+----++-+-+----++--+-+-+-+++-+-+---+------+/| |||| | | ||| || | |\+-+---++-++--++-+-+-++/|
|
||||||
|
| | | | | || | |||/-+-++-++\||| | || \++----++-+-+----++-+-+----++--+-+-/ ||| | | | | | |||| | | ||| || | \-+-+---++-/| || | | || |
|
||||||
|
| | | | | || | |||| | || |\++++--+-----++---++----++-+-+----++-+-+----++--+-+---+++-+-+---+------+-+-++++--+-+-+/| || | | | || | || | | || |
|
||||||
|
| | | | | || | |||| | || | |||| | || || || | | |\-+-+----++--+-+---+++-+-+---+------+-+-++++--+-+-+-+-++-+---+-+---+/ | || | | || |
|
||||||
|
| | | \-+-++-+-++++-+-++-+-++++--+-----++---++----+/ | | | | | || | | ||| | | | | | ||\+--+-+-+-+-++-/ | | | | || | | || |
|
||||||
|
| | | | || | |||| | || | |||| | || || | | \----+--+-+----/| | | ||| | | /+------+-+-++-+--+-+-+-+-++-----+\| | | || | | || |
|
||||||
|
| |/--+---+-++-+-++++-+-++-+-++++--+-\ || || | | | | | | \-+---+++-+-+--++------+-+-++-+--+-+-+-+-++-----+++---+---+--++-+-/ || |
|
||||||
|
| || | | || | |||| | || | |||| | | \+---++----+--+------+--+-+-----+----+---+++-+-+--++------+-+-++-+--+-+-+-+-++-----+++---+---+--++-/ || |
|
||||||
|
| || | | || \-++++-+-++-+-+/\+--+-+----+---++----+--+------+--+-+-----+----+---+++-+-+--++------+-+-++-+--/ | | | || ||| | | || || |
|
||||||
|
| || | | || |||| | || | | \--+-+----+---/| | | | | | \----+---/|| | | || | | || | | | | || ||| | | || || |
|
||||||
|
| || | | || |||| \-++-+-+-----+-+----+----+----+--+------+--+-+----------+----++-+-+--++------+-+-++-+----+-+-+-++-----++/ | | || || |
|
||||||
|
| || | | || |||| || | | | | | | | | | | | | || | | || | | || | | | | |\-----++----+---+--++-----++-/
|
||||||
|
\--++--+---+-/| |||\---++-+-/ | | | | | | | | | | || | | || /----+-+-++-+----+-+-+-+------++----+---+--++-\ ||
|
||||||
|
|| | | | ||| || | | v | | | | | | | | || | | || | | | || | \-+-+-+------++----+---+--++-+---+/
|
||||||
|
|| | | | ||| || | | | | | | | | | | | || | | \+-+----+-+-++-+------+-+-+-->---+/ | | || | |
|
||||||
|
|| | | | ||| \+-+-------+-+----+----+----+--+------+--+-+----------+----++-+-+---+-+----+-+-++-+------+-+-+------/ | | || | |
|
||||||
|
|| | | | ||| | | \-+----+----+----+--+------+--+-+----------+----++-+-+---+-+----+-+-++-+------+-+-+------------+---/ || | |
|
||||||
|
|| | | | ||| | | | \----+----+--+------+--+-+----------+----++-+-+---+-+----+-+-+/ | | | | | || | |
|
||||||
|
|| | \--+---+++-----+-+---------+---------+----+--+------+--+-+----------+----++-+-+---+-+----+-+-+--+------+-/ | | || | |
|
||||||
|
\+--+------+---++/ | | | | | | \--+-+----------/ || | | | | | | | | | | | || | |
|
||||||
|
| | \---++------+-+---------+---------+----+--+---------+-+---------------++-+-+---/ | | | | \------+---+------------+------/| | |
|
||||||
|
| | || | \---------+---------+----+--+---------+-+---------------++-+-+-----+----+-+-+---------+---/ | | | |
|
||||||
|
| | || | | | | \---------+-+---------------/| | | | | | | | | | | |
|
||||||
|
| | |\------+-----------+---------+----/ | | \-+-+-----+----+-+-+---------+----------------/ | | |
|
||||||
|
| | | \-----------+---------+-----------------+-+------------------+-+-----+----+-+-/ | | | |
|
||||||
|
\--+----------+-------------------/ | | | | \-----+----+-+-----------+------------------------/ | |
|
||||||
|
| | | | \------------------+-------+----+-+-----------+--------------------------+---/
|
||||||
|
| \-----------------------------+-----------------/ | | \-+-----------/ |
|
||||||
|
\----------------------------------------+--------------------------------------+-------+------/ |
|
||||||
|
\------------------------------------->/ \---------------------------------------------/
|
||||||
@@ -0,0 +1,267 @@
|
|||||||
|
// Accidentally named all the carts miners for some reason...
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var part int
|
||||||
|
flag.IntVar(&part, "part", 1, "part 1 or 2")
|
||||||
|
flag.Parse()
|
||||||
|
fmt.Println("Running part", part)
|
||||||
|
|
||||||
|
if part == 1 {
|
||||||
|
ans := part1(util.ReadFile("./input.txt"))
|
||||||
|
fmt.Println("Output:", ans)
|
||||||
|
} else {
|
||||||
|
ans := part2(util.ReadFile("./input.txt"))
|
||||||
|
fmt.Println("Output:", ans)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(input string) string {
|
||||||
|
grid, miners := parseInputs(input)
|
||||||
|
|
||||||
|
var collisionCoords map[[2]int]bool
|
||||||
|
for len(collisionCoords) == 0 {
|
||||||
|
collisionCoords = tick(grid, miners)
|
||||||
|
// fmt.Println(printGridWithMiners(grid, miners))
|
||||||
|
}
|
||||||
|
|
||||||
|
var coordString string
|
||||||
|
// should only be one entry, but range over the map to make it easier
|
||||||
|
// it's a map only because of how I wanted to handle part 2
|
||||||
|
for c := range collisionCoords {
|
||||||
|
coordString = fmt.Sprintf("%d,%d", c[1], c[0])
|
||||||
|
}
|
||||||
|
return coordString // X,Y i.e. COL, ROW
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(input string) string {
|
||||||
|
grid, miners := parseInputs(input)
|
||||||
|
|
||||||
|
for len(miners) > 1 {
|
||||||
|
collisionCoords := tick(grid, miners)
|
||||||
|
|
||||||
|
// remove all miners that have collided
|
||||||
|
if len(collisionCoords) > 0 {
|
||||||
|
// wholesale replacement of miners slice
|
||||||
|
remainingMiners := []*Miner{}
|
||||||
|
for _, m := range miners {
|
||||||
|
hasCollided := collisionCoords[m.coords]
|
||||||
|
if !hasCollided {
|
||||||
|
remainingMiners = append(remainingMiners, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
miners = remainingMiners
|
||||||
|
}
|
||||||
|
|
||||||
|
// fmt.Println(printGridWithMiners(grid, miners))
|
||||||
|
}
|
||||||
|
|
||||||
|
finalAnsCoords := miners[0].coords
|
||||||
|
return fmt.Sprintf("%d,%d", finalAnsCoords[1], finalAnsCoords[0]) // X,Y i.e. COL, ROW
|
||||||
|
}
|
||||||
|
|
||||||
|
type Miner struct {
|
||||||
|
coords [2]int
|
||||||
|
direction string
|
||||||
|
lastTurn int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Miner) Move() {
|
||||||
|
switch m.direction {
|
||||||
|
case "up":
|
||||||
|
m.coords[0]--
|
||||||
|
case "down":
|
||||||
|
m.coords[0]++
|
||||||
|
case "left":
|
||||||
|
m.coords[1]--
|
||||||
|
case "right":
|
||||||
|
m.coords[1]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleIntersection is for "+" cells
|
||||||
|
func (m *Miner) HandleIntersection() {
|
||||||
|
turns := []string{"left", "straight", "right"}
|
||||||
|
m.lastTurn++
|
||||||
|
m.lastTurn %= 3
|
||||||
|
|
||||||
|
turnDirection := turns[m.lastTurn]
|
||||||
|
if turnDirection == "straight" {
|
||||||
|
// do nothing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// get new direction
|
||||||
|
directions := []string{"left", "up", "right", "down"}
|
||||||
|
var index int
|
||||||
|
for i, d := range directions {
|
||||||
|
if d == m.direction {
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if turnDirection == "left" {
|
||||||
|
index--
|
||||||
|
} else if turnDirection == "right" {
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
|
||||||
|
index %= 4
|
||||||
|
if index < 0 {
|
||||||
|
index = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
m.direction = directions[index]
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseInputs(input string) (grid [][]string, miners []*Miner) {
|
||||||
|
// overwrite miners with their corresponding grid value
|
||||||
|
minerVals := map[rune]string{
|
||||||
|
'^': "|",
|
||||||
|
'v': "|",
|
||||||
|
'>': "-",
|
||||||
|
'<': "-",
|
||||||
|
}
|
||||||
|
minerDirections := map[rune]string{
|
||||||
|
'^': "up",
|
||||||
|
'v': "down",
|
||||||
|
'>': "right",
|
||||||
|
'<': "left",
|
||||||
|
}
|
||||||
|
lines := strings.Split(input, "\n")
|
||||||
|
for r, l := range lines {
|
||||||
|
if l == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
row := []string{}
|
||||||
|
// each line represents a row
|
||||||
|
for col, v := range l {
|
||||||
|
if minerVals[v] != "" {
|
||||||
|
row = append(row, minerVals[v])
|
||||||
|
miners = append(miners, &Miner{
|
||||||
|
coords: [2]int{r, col},
|
||||||
|
direction: minerDirections[v],
|
||||||
|
lastTurn: 2,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
row = append(row, string(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
grid = append(grid, row)
|
||||||
|
}
|
||||||
|
|
||||||
|
return grid, miners
|
||||||
|
}
|
||||||
|
|
||||||
|
// collision will not be "" if there is a collision
|
||||||
|
func tick(grid [][]string, miners []*Miner) (collisionCoords map[[2]int]bool) {
|
||||||
|
// sort miners into order of who will move first
|
||||||
|
sort.Slice(miners, func(i, j int) bool {
|
||||||
|
iCoords := miners[i].coords
|
||||||
|
jCoords := miners[j].coords
|
||||||
|
if iCoords[0] != jCoords[0] {
|
||||||
|
return iCoords[0] < jCoords[0]
|
||||||
|
}
|
||||||
|
return iCoords[1] < jCoords[1]
|
||||||
|
})
|
||||||
|
|
||||||
|
// map to detect collisions
|
||||||
|
minerCoords := map[[2]int]bool{}
|
||||||
|
// populate all coords to start because collisions don't necessarily happen
|
||||||
|
// after one or the other has moved
|
||||||
|
for _, m := range miners {
|
||||||
|
minerCoords[m.coords] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
collisionCoords = make(map[[2]int]bool)
|
||||||
|
for _, m := range miners {
|
||||||
|
coords := m.coords
|
||||||
|
|
||||||
|
// if a collision has already occured here, do not move this cart
|
||||||
|
if collisionCoords[coords] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch grid[coords[0]][coords[1]] {
|
||||||
|
case "/":
|
||||||
|
switch m.direction {
|
||||||
|
case "left":
|
||||||
|
m.direction = "down"
|
||||||
|
case "right":
|
||||||
|
m.direction = "up"
|
||||||
|
case "up":
|
||||||
|
m.direction = "right"
|
||||||
|
case "down":
|
||||||
|
m.direction = "left"
|
||||||
|
}
|
||||||
|
case "\\":
|
||||||
|
switch m.direction {
|
||||||
|
case "left":
|
||||||
|
m.direction = "up"
|
||||||
|
case "right":
|
||||||
|
m.direction = "down"
|
||||||
|
case "up":
|
||||||
|
m.direction = "left"
|
||||||
|
case "down":
|
||||||
|
m.direction = "right"
|
||||||
|
}
|
||||||
|
case "+":
|
||||||
|
m.HandleIntersection()
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove current coordinates (as moving off this cell)
|
||||||
|
minerCoords[m.coords] = false
|
||||||
|
|
||||||
|
m.Move()
|
||||||
|
|
||||||
|
// if a Miner is at the new coordinates, add a collision entry
|
||||||
|
if minerCoords[m.coords] {
|
||||||
|
collisionCoords[m.coords] = true
|
||||||
|
}
|
||||||
|
// update coordinates in map
|
||||||
|
minerCoords[m.coords] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return collisionCoords
|
||||||
|
}
|
||||||
|
|
||||||
|
// helper func to watch the miners move
|
||||||
|
func printGridWithMiners(grid [][]string, miners []*Miner) string {
|
||||||
|
minerDirections := map[string]string{
|
||||||
|
"up": "^",
|
||||||
|
"down": "v",
|
||||||
|
"right": ">",
|
||||||
|
"left": "<",
|
||||||
|
}
|
||||||
|
str := ""
|
||||||
|
|
||||||
|
mapMinerCoords := map[[2]int]*Miner{}
|
||||||
|
for _, m := range miners {
|
||||||
|
mapMinerCoords[m.coords] = m
|
||||||
|
}
|
||||||
|
|
||||||
|
for r, row := range grid {
|
||||||
|
for c, val := range row {
|
||||||
|
if m, ok := mapMinerCoords[[2]int{r, c}]; ok {
|
||||||
|
str += minerDirections[m.direction]
|
||||||
|
} else {
|
||||||
|
str += val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str += "\n"
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tests1 = []struct {
|
||||||
|
name string
|
||||||
|
want string
|
||||||
|
input string
|
||||||
|
// add extra args if needed
|
||||||
|
}{
|
||||||
|
{"example", "7,3", `/->-\
|
||||||
|
| | /----\
|
||||||
|
| /-+--+-\ |
|
||||||
|
| | | | v |
|
||||||
|
\-+-/ \-+--/
|
||||||
|
\------/
|
||||||
|
`},
|
||||||
|
{"actual", "5,102", util.ReadFile("input.txt")},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPart1(t *testing.T) {
|
||||||
|
for _, test := range tests1 {
|
||||||
|
t.Run(test.name, func(*testing.T) {
|
||||||
|
got := part1(test.input)
|
||||||
|
if got != test.want {
|
||||||
|
t.Errorf("got %v, want %v", got, test.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests2 = []struct {
|
||||||
|
name string
|
||||||
|
want string
|
||||||
|
input string
|
||||||
|
// add extra args if needed
|
||||||
|
}{
|
||||||
|
{"example", "6,4", `/>-<\
|
||||||
|
| |
|
||||||
|
| /<+-\
|
||||||
|
| | | v
|
||||||
|
\>+</ |
|
||||||
|
| ^
|
||||||
|
\<->/
|
||||||
|
`},
|
||||||
|
{"actual", "46,45", util.ReadFile("input.txt")},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPart2(t *testing.T) {
|
||||||
|
for _, test := range tests2 {
|
||||||
|
t.Run(test.name, func(*testing.T) {
|
||||||
|
got := part2(test.input)
|
||||||
|
if got != test.want {
|
||||||
|
t.Errorf("got %v, want %v", got, test.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+235
@@ -0,0 +1,235 @@
|
|||||||
|
|
||||||
|
--- 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.
|
||||||
|
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
There isn't much you can do to prevent crashes in this ridiculous system. However, by predicting the crashes, the Elves know where to be in advance and instantly remove the two crashing carts the moment any crash occurs.
|
||||||
|
|
||||||
|
|
||||||
|
They can proceed like this for a while, but eventually, they're going to run out of carts. It could be useful to figure out where the last cart that hasn't crashed will end up.
|
||||||
|
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
|
||||||
|
/>-<\
|
||||||
|
| |
|
||||||
|
| /<+-\
|
||||||
|
| | | v
|
||||||
|
\>+</ |
|
||||||
|
| ^
|
||||||
|
\<->/
|
||||||
|
|
||||||
|
/---\
|
||||||
|
| |
|
||||||
|
| v-+-\
|
||||||
|
| | | |
|
||||||
|
\-+-/ |
|
||||||
|
| |
|
||||||
|
^---^
|
||||||
|
|
||||||
|
/---\
|
||||||
|
| |
|
||||||
|
| /-+-\
|
||||||
|
| v | |
|
||||||
|
\-+-/ |
|
||||||
|
^ ^
|
||||||
|
\---/
|
||||||
|
|
||||||
|
/---\
|
||||||
|
| |
|
||||||
|
| /-+-\
|
||||||
|
| | | |
|
||||||
|
\-+-/ ^
|
||||||
|
| |
|
||||||
|
\---/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
After four very expensive crashes, a tick ends with only one cart remaining; its final location is 6,4.
|
||||||
|
|
||||||
|
|
||||||
|
What is the location of the last cart at the end of the first tick where it is the only cart left?
|
||||||
|
|
||||||
Reference in New Issue
Block a user