From ac968e8ea23d75d04fa723fff3f4ccff216a524b Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Wed, 19 Dec 2018 10:57:54 -0500 Subject: [PATCH 1/3] day 13 solution --- 2018/day13/Cargo.lock | 4 + 2018/day13/Cargo.toml | 7 ++ 2018/day13/input | 150 +++++++++++++++++++++++++++++++ 2018/day13/src/main.rs | 197 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 358 insertions(+) create mode 100644 2018/day13/Cargo.lock create mode 100644 2018/day13/Cargo.toml create mode 100644 2018/day13/input create mode 100644 2018/day13/src/main.rs diff --git a/2018/day13/Cargo.lock b/2018/day13/Cargo.lock new file mode 100644 index 0000000..da4efb4 --- /dev/null +++ b/2018/day13/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "day13" +version = "0.1.0" + diff --git a/2018/day13/Cargo.toml b/2018/day13/Cargo.toml new file mode 100644 index 0000000..ccd558f --- /dev/null +++ b/2018/day13/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "day13" +version = "0.1.0" +authors = ["Andrew Coleman "] +edition = "2018" + +[dependencies] diff --git a/2018/day13/input b/2018/day13/input new file mode 100644 index 0000000..6f70ca2 --- /dev/null +++ b/2018/day13/input @@ -0,0 +1,150 @@ + /-------------------------------------\ + /----------------------------------\ /---------------+-------------------------------------+--------\ + /+----------------------------------+-------------------+---------------+----------------------------------\ | | + || /---------+-------------------+-\ /-----------+--------------\ | | | /--------\ + || /------+--\ | /------+-+-+-----------+--------------+--------------\ | | | | | + || | | | |/-----------+------+-+-+-----------+--------------+--------------+----+--+--\ | | | + || /---------------+------+--+------++-----------+--\ | | | | /-------+----\ | | | | | | | + || | /---+------+--+-\ || | | | | | | | | /+---------+----+--+--+-----+-\ | | + || | | | | | | || | | | | | | /-+-------+---++---------+----+--+--+-----+-+--+\ | + || | | | | | | || | /+---+-+-+-----------+----+-+-------+---++\ | | | | | | || | + || | | /-+------+--+-+----++-----------+\|| | | | | | |/------+---+++--------+----+--+\ | | | || | + || | | | | | | | || |||| | | | | | || | ||| | | || | | | || | + || | | | | /----+--+-+----++-----------++++---+-+-+-----------+----+-++--\ | ||| | |/-++-+-----+-+--++-------+----\ +/--------++-+-----------+-+-+-+----+--+-+----++-----------++++---+-+-+----\ | |/++--+---+---+++--------+----++-++-+-----+-+\ || | | +| || | /-+-+-+-+----+--+-+----++------\ |||| | | | | | |||| | | ||| | || || | | || || | | +| || | | | | | | | | | || | |||| | | | /--+------+----++++--+---+---+++--------+----++\|| | | || || | | +| /---++-+-------\ | | | | | | | | || | |||| | | | | | | |||| | | ||| /------+----+++++-+-----+-++-++-----\ | | +| | || | | | | | | | | | | /++------+----++++-\ | | | | | | |||| | | ||| | | ||||| | | || || | | | +| | || | | | | | | | | | | ||| | ||||/+-+-+-+-+--+------+----++++--+---+---+++-+------+----+++++-+---\ | || || | | | +| | || | /---+-+-+-+-+-+----+-\| | ||| | |||||| | | | | | | |||| | | ||| | /---+----+++++-+---+-+-++-++-----+-+-\ | +|/---+---++-+---+---+-+-+-+-+-+----+-++-+---+++------+----++++++-+-+\| | | | |||| | | ||| | | | ||||| | | | || || | | | | +|| | || | | | | | | | | | || | /+++------+----++++++-+-+++-+--+------+----++++--+---+---+++-+--+---+----+++++-+---+-+-++-++---\ | | | | +|| | || | | | | | | | | | || | |||| | |||||| | ||| | | | |||| | | ||| | | | ||||| | | | || || | | | | | +|| | || | | | | | | | | | || | |||| | /--++++++-+-+++-+--+------+----++++--+---+---+++-+-\| | ||||| | | | || || ^ | | | | +|| | |v | | | | | | | | | || | |||| | | |||||| | ||| | | | |||| | | ||| | || | ||||| | |/+-++-++---+-+-+-+\ | +|| | || | | /+-+-+-+-+-+----+-++-+--++++------+-+--++++++-+\||\-+--+------+----++++--+---//--+++-+-++---+--\ ||||| | ||| || \+---+-+-/ || | +|| | || | | || | | | \-+----+-+/ | |||| | | |||||| |||| /+--+----\ | |||| | | ||| | || | | ||||| | ||| || | | | || | +||/--+---++-+---+--++-+-+-+---+----+-+--+-\|||| | | |||||| |||| || | | | |||| | | ||| | || |/-+-+++++-+--\||| || | | | || | +||| | \+-+---+--++-+-+-+---+----+-+--+-+++++------+-+--++++++-++++-++--+----+-+----++++--+----+--+++-+-++---++-+-/|||| | |||| || | | | || | +|||/-+----+-+---+--++-+-+-+---+--\ | | | ||||| | | |||||| |||| || | /--+-+----++++--+----+--+++-+-++---++-+-\|||| | |||| || | | | || | +\+++-+----+-+---+--++-+-+-+---+--+-+-+--+-+++++------+-+--++++++-++++-++--/ | | | |||| /+----+--+++-+-++---++-+\||||| | |||| || | | | || | + ||| | | | | || | | | | | | | | ||||| |/+--++++++-++++-++----+--+-+\ |||| || | ||| | || || ||||||| | |||| || | | | || | + ||^ | | | | || | \-+---+--+-+-+--/ ||||| ||| |||||| |||| || | | || |||| || | ||| | || || ||||||| | |||| || | | | || | + ||| | | | |/-++-+---+---+--+-+-+----+++++------+++--++++++-++++-++----+\ | || |||| || | ||| | || ||/+++++++-+--++++-++--+---+\| || | + ||| | /--+-+---++-++\| | | | | | ||||| ||| \+++++-++++-++----++-+-++---++++-++----+--+++-+-++---/||||||||| | |||| || | ||| || | + ||| | | | | || |||| | | | | | ||||| ||| /-+++++-++++-++----++\| || /-++++-++----+--+++-+-++----+++++++++-+--++++\|| | ||| || | + ||| | | | | || |||| | |/-+-+-+----+++++------+++-+-+++++-++++-++----++++-++-+-++++-++----+--+++-+-++----+++++++++-+--+++++++--+-\ ||| || | + ||| | | | | ||/++++---+---++-+-+-+----+++++------+++-+-+++++-++++-++----++++-++-+-++++-++----+--+++-+-++\ ||||||||| | ||||||| | | ||| || | + ||| | | | | ||||||| | /-++-+-+-+----+++++\ ||| | ||||| |||| || |||| || | |||| || | ||| | ||| \++++++++-+--/|||||| | | ||| || | + ||| | | | | ||||||| | | || |/+-+----++++++-----+++-+-+++++-++++-++----++++-++-+-++++-++----+--+++-+-+++----++++++++-+---++++++--+-+\||| || | + ||| | | | | ||||||| | | || ||| | /-++++++-----+++-+-+++++-++++-++----++++-++-+-++++-++----+--+++-+-+++-\/-++++++++\| |||||| | ||||| || | + ||| | | | | ||||||| | | || ||| | | |||||| ||| | ||||| |||| || |||| || | ||||/++----+--+++\| ||| || |||||||||| |||||| | ||||| || | + ||| | | | | ||||||| | | || ||| | | ||||||/----+++-+-+++++-++++-++----++++-++\| ||||||| | ||||| ||| || |||||||||| |||||| | ||||| || | + |||/+-+--+-+-\ ||||||| | | || ||| | | ||||||| ||| | ||||| |||| || |||| |||| ||||||| | ||||| ||| || |||||||||| |||||| | ||||| || | + |||||/+--+-+-+-+++++++---+-+-++-+++-+--+-+++++++----+++-+-+++++-++++-++----++++-++++-+++++++----+--+++++-+++-++\|||||||||| |||||| | ||^|| || | + ||||||| | | | ||||||| | | || ||| | | ||||||| ||| | ||||| |||| || |||| |||| ||||||| | |||||/+++-+++++++++++++---++++++--+-+++++---++-+\ + ||||||| | | | ||||||| | | || ||| | | ||||||| ||| | |||\+-++++-++----++++-++++-+++++++----+--+++++++++-+++++++++++++---/||||| | ||||| || || + ||||||| | | | ||||||| | | || |||/+--+-+++++++----+++-+-+++-+-++++-++----++++-++++-+++++++--\ | ||||||||| ||||||||||||| ||||| | ||||| || || + ||||||| | | | ||||||| | | || ||\++--+-+++++++----+++-+-+++-+-++/| || |||| |||| ||||||| /+-+--+++++++++-+++++++++++++---\||||| | ||||| || || + ||||||| | | | |||\+++---+-+-++-++-++--+-+++++++----+++-+-+++-+-+/ | || |||| |||| ||||||| || | ||||||||| ||||||||||||| |||||| | ||||| || || + ||^|||| | | | ||| ||| | | || || || | ||||||| ||| | ||| | | | || |||| |||| |||||\+-++-+--+++++++++-+++++/||||||| |||||| | ||||| || || + ||||||| | | | ||| |||/--+-+-++-++-++--+-+++++++----+++-+-+++-+-+\ | || |||| |||| ||||| | || | ||||||||| ||||| ||||||| |||||| | ||||| || || + |||\+++--+-+-/ ||| |||| | | || || || | ||||||| ||| | ||| | || | || |||| |||| ||||| | || | |||||||\+-+++++-+++++++---++++++--+-+++++---/| || + ||| ||| | | ||| |||| | | || || || | ||||||| ||| | ||| | || | || |||| |||| ||||| | || | ||||||| | ||||| ||||||| |||||| | ||||| | || + ||| ||| | | ||| |||| | | || || || | |||||||/---+++-+-+++-+-++-+-++----++++-++++-+++++-+-++-+--+++++++-+-+++++\||||||| |||||| | ||||| | || + ||| ||| | | ||| |||| | | || || || | |||||||| ||| | ||| | || | || |||| |||| ||||| | || | ||||||| | ||||||||||||| |||||| | ||||| | || + ||| ||| | | ||| |||| | | || || || | |||||||| ||| | |\+-+-++-+-++----++++-++++-+++++-+-++-+--++/|||| | ||||||||||||| |||||| | ||||| | || + ||| ||| |/+---+++-++++--+-+-++-++-++--+-++++++++---+++-+\| | | || | || |||| |||| ||||| | || | || |||| | ||||||||||||| |||||| | ||||| | || + ||| ||| ||| ||| |||| | | || || || /+-++++++++---+++-+++-+-+-++-+-++----++++-++++-+++++-+-++-+--++-++++-+-+++++++++++++---++++++--+-+++++--\ | || + ||| ||| ||| ||| |||| /+-+-++-++-++-++-++++++++---+++-+++-+-+-++-+-++----++++-++++-+++++-+-++-+--++-++++-+-+++++++++++++---++++++\ | ||||| | | || + ||| ||| ||| ||| |||| || |/++-++-++-++-++++++++---+++-+++-+-+-++-+-++----++++-++++-+++++-+-++-+--++\|||| | ||||||||^|||| ||||||| | ||||| | | || + ||| ||| ||| ||| |||| || |||| || || || ||||\+++---+++-+++-+-+-++-+-++----++++-++++-+++++-+-++-+--+++++++-+-++++++++++++/ ||||||| | ||||| | | || + ||| ||| ||| ||| ||\+-++-++++-++-++-++-++++-+++---/|| ||| | | || | || |||| |||| ||||| | \+-+--+++++++-+-++++++++++++----/|||||| | ||||| | | || + ||| ||| ||| ||| || | || |||| || || || |||| |||/---++-+++-+-+-++-+-++-\ |||| |||| ||||| | | | ||||||| | |\+++++++++/ |||||| | ||||| | | || + ||| ||| ||| ||| || | || |||| || || || |||| |||| || ||| | | ||/+-++-+--++++-++++-+++++-+--+-+--+++++++-+-+-+++++++++------++++++-+-+++++--+-+\|| + ||| ||| ||| ||| || | || |||| || || || |||| |||| || ||| | | |||| || | |||| |||| ||||| | | | ||||||| | | ||||||||| |||||| | ||||| | |||| + ||| ||\--+++---+++-+/ | || |||| || || || |||| |||| ^| ||| | | |||| || | |||| |||| ||||| | | | ||||||| | | ||||||||| |||||| | ||||| | |||| + ||| || ||| ||| | | || |||| || || || |||| |||| || \++-+-+-++++-++-+--++/| |||| v|||| |/-+-+--+++++++-+-+-+++++++++\ |||||| | ||||| | |||| + ||| || ||| ||| | | || |||| || || || |||| |||| \+--++-+-+-++++-++-+--++-+-+/|| |||||/++-+-+--+++++++-+-+-++++++++++\ |||||| | ||||| | |||| + ||| || ||| ||| | | || |||| || || || |||| |||| |/-++-+-+-++++\|| | || | | || |||||||| | | ||||||| | | ||||||||||| |||||| | ||||| | |||| + |||/++---+++\ ||| | | || |||| || || ||/++++-++++----++-++-+-+-+++++++-+--++-+-+-++-++++++++-+-+--+++++++-+-+-+++++++++++--\ |||||| | ||||| | |||| + |||||| |||| ||| | | ^| |||| || ||/+++++++-++++----++-++-+-+-+++++++-+--++-+-+-++-++++++++-+-+--+++++++-+-+-+++++++++++--+-++++++\| ||||| | |||| + |||||| |||| ||| | | || ||||/++-++++++++++-++++----++-++-+-+-+++++++-+--++-+-+-++-++++++++-+-+->+++++++-+-+-+++++++++++--+-++++++++\||||| | |||| + |||||| |||| ||| | | || ||||||| |||||||||| |||| || || | | ||||||| | || | | || |||||||| | | ||||||| | | ||||||||||| | |||||||||||||| | |||| + |||||| |||| ||| | | || ||||||| |||||||||| |||| || || | | ||||||| | || | | || ||\+++++-+-+--+/||||| | | ||||||||||| | |||||||||||||| | |||| + |||||| |||| ||| | | || |\+++++-++++++++++-++++----++-++-+-+-+++++++-+--++-+-+-++-++-+++++-+-+--+-/|||| | | ||||||||||| | |||||||||||||| | |||| + |||||| |||| ||| | | || | ||||| |||||||||| |||| || || | | ||||||| | || | | || || ||||\-+-+--+--++++-+-+-+++++++++/| | |||||||||||||| | |||| + |||||| |||| ||| | | || | ||||| |||\++++++-++++----++-++-+-+-+++++++-+--++-+-+-++-++-++++--+-+--+--++++-+-+-+++++++++-+--+-++++++++++++++--/ |||| + |||||| |||| ||| | | ||/+-+++++-+++-++++++-++++----++-++-+-+-+++++++-+--++-+-+-++-++-++++--+-+--+--++++-+-+-+++++++++-+\ | |||||||||||||| |||| + |||||| |||| ||| | | |||\-+++++-+++-++++++-/||| || || | |/+++++++-+--++-+-+-++-++-++++--+-+--+--++++-+\| ||||||||| || | |||||v||||||v| |||| + |||||| \+++--+++-+--+-+++--+++++-+++-+++++/ ||| || || | ||||||||| | \+-+-+-++-++-++++--+-+--+--++++-+++-++++/|||| || | |||||||||||||| |||| + |||||| ||| ||| | | ||| ||||| ||| ||||| ||| || || | ||||||||| | | | | || || |||| | | | |||| ||| |||| |||| || | |||||||||||||| |||| +/++++++----+++--+++-+--+-+++--+++++-+++-+++++---+++----++-++-+-+++++++++-+\ | | |/++-++-++++--+-+--+--++++-+++-++++\|||| || | |||||||||||||| |||| +||||||| ||| ||| | | \++--+++++-+++-+++++---+++----++-++-+-+++++++++-++--+-+-++++-++-++++--+-+--+--++++-+++-+++++++++-++-+-+++++/|||||||| |||| +||||||| ||| ||| | | || ||||| |||/+++++---+++----++\||/+-+++++++++-++--+-+-++++-++-++++--+-+--+--++++-+++-+++++++++-++-+-+++++-++++++++\ |||| +||||||| ||| ||| | | || ||||| ||||||||| ||| |||||||/+++++++++-++--+-+\|||| || |||| | | | |||| ||| ||||||||| || | ||||| ||||||||| |||| +||||||| ||| ||| | | || \++++-+++++++++---+++----+++++++++++++++++-++--+-++++++-++-+++/ | | \--++++-+++-+++++++++-++-+-+++/| ||||||||| |||| +|||||||/---+++--+++-+--+--++---++++-+++++++++---+++----+++++++++++++++++-++--+-++++++-++-+++--\| | |||| ||| ||||||||| || | ||| | ||||||||| |||| +|||||||| ||| \++-+--+--++---++++-+/||||||| ||| \++++++++++++++++-++--+-++++++-++-+++--++-+-----+++/ ||| ||||||||| || | ||| | ||||||||| |||| +|||||||| ||| || | | || |||| | ||||||\---+++-----+++++++/|\++++++-++--+-++++++-++-+++--++-+-----+++--+++-+++++++++-++-+-+/| | ||||||||| |||| +|||||||| ||| || | | || |||| | |||||| ||| ||||||| | |||||| || | |||||| || ||| || | /+++--+++<+++++++++-++\| | | | ||||||||| |||| +|||||||| ||| || | | || |||| | |||||| ||| ||||||| | |||||| || | |||||| || ||| || | |||| ||| ||||||||| |||| | | | ||||||||| |||| +||||||||/--+++---++\| | || |||| | |||||| ||| ||||||| | |||||| || | ||\+++-++-+++--++-+----++++--+++-+++++++/| |||| | | | ||||||||| |||| +||||||||| ||| |||| | || |||| | |||||| \++-----+++++++-+-++++++-++--+-++-+/| || ||| || | |||| ||| ||||||| | |||| | | | ||||||||| |||| +||||||||| ||| |||| | || |||| | |||||| || ||||||| | |||||| || | || | | || ||| /++-+----++++--+++-+++++++-+\|||| | | | ||||||||| |||| +||||||||| ||| |||| | || |||| | |\++++-----++-----+/||||| | |||||| || | || | | || ||| ||| | |||| ||| ||||||| |||||| | | | ||||||||| |||| +||||||||| ||| |||| | || |||| | | ||||/----++-----+-+++++-+-++++++-++--+-++-+-+\|| ||| ||| | |||| ||| |||||\+-++++++-+-+-+-+++++++++---++/| +||||||||| ||| |||| | || |||\-+-+-+++++----++-----+-+++++-+-++++++-++--+-++-+-++++-+++-+++-+----++++--+++-+++++-+-++++++-+-+-+-++++/|||| || | +||||||||| ||| /-++++--+--++---+++--+-+-+++++---\|| \-+++++-+-+++/|| || | || | |||| ||| ||| | |||| ||| ||||| | |||||| | | | |||| |||| || | +|||||\+++--+++-+-+++/ | |\---+++--+-+-+++++---+++-------+++++-+-+++-++-++--+-++<+-++++-+++-+++-+----++++--+++-+++++-+-+++/|| | | | |||| |||| || | +|||\+-+++--+++-+-+++---+--+----++/ | | ||||| ||| ||||| | ||| || || | || | |||| ||| ||| | |||| ||| ||||| | ||| || | | | |||| |||| || | +||| | ||| ||| | ||| | | || | | ||||| ||| ||||| | ||| || || | || | |||| ||| ||| \----++++--+++-++/|| | ||| || | | | |||| |||| || | +||| | ||| ||| | \++---+--+----++---+-+-+++++---+++-------+++++-+-+++-++-++--/ || | |||| \++-+++------++++--+++-++-++-+-/|| || | | | |||| |||| || | +||| | ||| ||| | || | | /++---+-+\||||| ||| ||||| | ||| || || || | ||\+--++-+++------++++--+++-++-++-+--++-++-+-+-+-+/|| |||| || | +||| | ||| ||| | || | | ||| | ||||||| ||| ||||| | ||| || || /--++-+-++-+--++-+++------++++--+++-++-++\| || || | | | | || |||| || | +||| | ||| |\+-+--++---+--+---+++---+-+++++++---+++-------+++/| | ||| |\-++-+--++-+-++-+--++-+++------++++--+++-++-+++/ || || | | | | || |||| || | +||| | ||| | | | || | | ||| | ||||||v ||| ||| | | ||| | || | || | || | || ||| |||| ||| || ||| || || | | | | || |||| || | +||| | ||| | | | || | \---+++---+-+++++++---+++-------+/| | | ||| | || | || | || | || ||| |||| ||| || ||| || || | | | | || |||| || | +||| | ||| | | |/-++---+---\ ||| | ||||||| ||| | | | | ||| | || | || | || | || ||| \+++--+++-++-+++---++-/| | | | | || |||| || | +||| | ||| | | || || | | ||| | ||||||| /+++------\| | | | ||| | || | || | || | || ||| ||| ||| || ||| || | | | | | || |||| || | +||| | ||| | | || || | | ||| | ||\++++--++++------++-+-+-+-+++-+--++-+--++-+-++-+--++-+++-------+++--++/ || ||| || | | | | | || |||| || | +||| | ||| | | || || | | ||| /+-++-++++--++++------++-+-+-+-+++-+--++-+--++-+-++-+-\|| ||| ||| /++--++-+++---++--+-+-+-+-+-++-++++--\|| | +||| \-+++--+-/ || || | | ^|\--++-++-++++--++++------++-+-+-+-+++-+--++-+--++-+-++-+-+++-+++-------+++-+++--++-+++---++--+-+-+-+-+-/| |||| ||| | +|\+---+++--+---++-++---+---+--++---++-++-++++--++++------++-+-+-+-++/ | || | || | || | ||| ||| ||| ||| || ||| || | | | | | | |||| ||| | +\-+---+++--+---++-++---+---+--++---++-++-++++--++++------++-+-+-+-++--+--+/ | || \-++-+-+++-+++-------+++-+++--++-+/| || | | | | | | |||| ||| | + | ||| /+---++-++---+---+--++---++-++-++++--++++------++-+-+-+-++--+--+--+--++--\|| | ||| ||| ||| ||| || | | || | | | | | | |||| ||| | + | ||| || ||/++---+---+--++---++-++-++++--++++------++-+-+-+-++--+-\| \--++--+++-+-+++-+++-------+++-+++--++-+-/ || | | | | | | |||| ||| | + | ||| || |\+++---+---/ || || || |||| |||| || | | | || | || || ||| | ||\-+++-------+++-+++--++-+-----+/ | | | | | | |||| ||| | + | ||| || | ||| | || || || |||| |||| || | | | || | || || ||| \-++--+++-------+++-+++--++-+-----+---+-+-+-/ | | |||| ||| | +/-+---+++-++--\| ||| | /-++---++-++-++++--++++------++-+-+-+-++\ | || || ||| || ||| ||| ||| || | | | \-+---+--+-++++--+/| | +| | ||| || || ||| | | || || || |||| |||| || | | | ||| | || || ||| || ||| ||| ||| || | | | | | | |||| | | | +| | ||| || || ||| | | || || || |||| |||| || | | | ||| | || || ||| || ||| |\+-+++--++-+-----+---+---+---+--+-++/| | | | +| \---+++-++--++-+++---+----+-++---++-++-+/|| |||| || | | | |\+-+-++-----++--+++---++--+++-------+-+-+++--++-+-----+---+---+---+--+-++-+--+-/ | +| ||| || || ||| | | \+---++-+/ | || |||| || | | | | | | || || |||/--++--+++-------+-+-+++--++-+-----+--\| | | | || | | | +| ||| || || ||| | | | || | | || |||| || | | | | | | || || |||| || ||| | | ||| || | | || | | | || | | | +| ||| || || ||| | | | || | \-++--++++------++-+-+-+-+-+-+-++-----++--++++--++--+++-------+-+-+++--++-+-----+--+/ | | | || | | | +| ||| || || \++---+----+--+---++-+----++--++++------++-+-+-+-+-+-+-/| || |||| || ||| | | ||| || | | | | | | || | | | +| ||| || || || | | | || | \+--++++------++-+-+-+-+-+-+--+-----++--++++--++--+++-------+-+-+++--++-+-----+--+----+---+--+-/| | | | +| ||| || || || | | \---++-+-----+--++++------++-+-+-+-+-+-+--+-----++--++++--++--+++-------+-+-+++--++-+-----+--+----+---+--/ | | | | +\-----+++-++--/| || | | || \-----+--++++------++-+-+-+-+-+-+--+-----++--++++--++--+++-------+-+-+++--++-+-----+--+----+---/ | | | | + ||| || | || | | || | |||| || \-+-+-+-+-+--+-----++--++++--++--+++-------+-+-+++--++-+-----+--+----+---------+-/ | | + ||| \+---+--++---+----+------++-------+--++++------++---+-+-+-+-+--+-----++--/||| || ||| | | ||| || | | | | | | | + ||| \---+--++---+----+------++-------+--++++------+/ | | | | \--+-----/| ||| || ||| /---+-+-+++--++-+-----+--+----+----\ | | | + ||| | || | | || | |||| | | | | | | | ||| || \++---+---+-+-+++--++-+-----/ | | | | | | + ||| | || | | || | |||\------+----+-+-+-+----/ | ||| || || | | | ||| || | | | | | | | + ||| | || | | || | ||| | \-+-+-+-----------/ ||| |\---++---+---/ | \++--++-+--------+----+----+----+----/ | + ||| | || | | |\-------+--+++-------+------+-+-+---------------+++--+----+/ | | || || | | | | | | + ||| | || \----+------+--------+--+++-------+------+-/ | \++--+----+----+-----+--++--++-+--------+----/ | | | + |\+------+--++--------+------+--------+--+++-------+------+---+----------------++--+----/ | | || |\-+--------+---------+----/ | + | \------+--+/ \------+--------+--+++-------+------+---/ |\--+---------+-----+--++--+--+--------/ | | + \--------+--+----------------+--------+--+++-------+------+--------------------+---+---------+-----+--++--/ | | | + | | | | ||| | | | | \-----+--++-----+----------<-------/ | + \--+----------------+--------+--+/| | | | | | || | | + \----------------+--------+--+-+-------+------+--------------------+---+---------------+--/| | | + | | | | | | | | | | | | + | | \-+-------/ | | | | | | | + | | | \--------------------+---+---------------+---/ | | + | \----+-----------------------------------/ | \---------+--------------------------------/ + | \---------------------------------------+-------------------------/ + \-----------------------------------------------------/ diff --git a/2018/day13/src/main.rs b/2018/day13/src/main.rs new file mode 100644 index 0000000..2f37172 --- /dev/null +++ b/2018/day13/src/main.rs @@ -0,0 +1,197 @@ +use std::fs::File; +use std::io::{BufRead, BufReader}; + +const MAP_SIZE: usize = 150; + +#[derive(Debug, Clone)] +struct Cart { + x: usize, + y: usize, + x_delta: i8, + y_delta: i8, + intersection: u8, + removed: bool +} + +impl Cart { + pub fn turn_right(&mut self) { + if self.x_delta == 0 { + if self.y_delta == 1 { + self.x_delta = -1; + } else { + self.x_delta = 1; + } + self.y_delta = 0; + } else { + if self.x_delta == 1 { + self.y_delta = 1; + } else { + self.y_delta = -1; + } + self.x_delta = 0; + } + } + + pub fn turn_left(&mut self) { + if self.x_delta == 0 { + if self.y_delta == 1 { + self.x_delta = 1; + } else { + self.x_delta = -1; + } + self.y_delta = 0; + } else { + if self.x_delta == 1 { + self.y_delta = -1; + } else { + self.y_delta = 1; + } + self.x_delta = 0; + } + } + + pub fn change_direction_at_intersection(&mut self) { + match self.intersection { + 0 => self.turn_left(), + 2 => self.turn_right(), + _ => {} + } + self.intersection = (self.intersection + 1) % 3; + } +} + +fn find_collision(map: &[[char; MAP_SIZE]; MAP_SIZE], carts: &mut Vec, find_last: bool) -> (usize, usize, u32) { + let mut ticks = 0; + let cart_len = carts.len(); + loop { + carts.sort_by(|a, b| { + if a.y == b.y { + a.x.cmp(&b.x) + } else { + a.y.cmp(&b.y) + } + }); + + for i in 0..cart_len { + if carts[i].removed { + continue; + } + let next_x = carts[i].x + carts[i].x_delta as usize; + let next_y = carts[i].y + carts[i].y_delta as usize; + + for j in 0..cart_len { + if i != j && !carts[j].removed && carts[j].x == next_x && carts[j].y == next_y { + if find_last { + carts[j].removed = true; + carts[i].removed = true; + } else { + return (next_x, next_y, ticks); + } + } + } + + match map[next_x][next_y] { + '/' => { + if carts[i].x_delta == 0 { + carts[i].turn_right(); + } else { + carts[i].turn_left(); + } + }, + '\\' => { + if carts[i].x_delta == 0 { + carts[i].turn_left(); + } else { + carts[i].turn_right(); + } + }, + '+' => { + carts[i].change_direction_at_intersection(); + }, + ' ' => { + panic!("off the rails!"); + }, + _ => {} + } + carts[i].x = next_x; + carts[i].y = next_y; + + if find_last { + let mut remaining_count = 0; + let mut remaining_index = 0; + for j in 0..cart_len { + if carts[j].removed == false { + remaining_count += 1; + remaining_index = j; + } + } + if remaining_count == 1 { + return (carts[remaining_index].x, carts[remaining_index].y, ticks); + } + } + } + ticks += 1; // gross + } +} + +fn main() { + let lines: Vec = BufReader::new(File::open("input").unwrap()) + .lines() + .map(|line| line.unwrap()) + .collect(); + let mut map = [[' '; MAP_SIZE]; MAP_SIZE]; + let mut carts: Vec = Vec::with_capacity(20); + let mut line_number = 0; + for line in lines.iter() { + for (j, c) in line.char_indices() { + if c == 'v' { + carts.push(Cart { + x: j, + y: line_number, + x_delta: 0, + y_delta: 1, + intersection: 0, + removed: false + }); + map[j][line_number] = '|'; + } else if c == '^' { + carts.push(Cart { + x: j, + y: line_number, + x_delta: 0, + y_delta: -1, + intersection: 0, + removed: false + }); + map[j][line_number] = '|'; + } else if c == '<' { + carts.push(Cart { + x: j, + y: line_number, + x_delta: -1, + y_delta: 0, + intersection: 0, + removed: false + }); + map[j][line_number] = '-'; + } else if c == '>' { + carts.push(Cart { + x: j, + y: line_number, + x_delta: 1, + y_delta: 0, + intersection: 0, + removed: false + }); + map[j][line_number] = '-'; + } else { + map[j][line_number] = c; + } + } + line_number += 1; + } + let (x, y, ticks) = find_collision(&map, &mut carts.clone(), false); + println!("found collision at {},{} after {} ticks", x, y, ticks); + let (x, y, ticks) = find_collision(&map, &mut carts.clone(), true); + println!("found last remaining cart at {},{} after {} ticks", x, y, ticks); +} From c164070d19e765029aafd02aa0385b8a4e34bed3 Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Thu, 20 Dec 2018 10:25:11 -0500 Subject: [PATCH 2/3] day 14 solution --- 2018/day14/Cargo.lock | 4 ++++ 2018/day14/Cargo.toml | 7 ++++++ 2018/day14/input | 1 + 2018/day14/src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 2018/day14/Cargo.lock create mode 100644 2018/day14/Cargo.toml create mode 100644 2018/day14/input create mode 100644 2018/day14/src/main.rs diff --git a/2018/day14/Cargo.lock b/2018/day14/Cargo.lock new file mode 100644 index 0000000..90e7534 --- /dev/null +++ b/2018/day14/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "day14" +version = "0.1.0" + diff --git a/2018/day14/Cargo.toml b/2018/day14/Cargo.toml new file mode 100644 index 0000000..b6d9962 --- /dev/null +++ b/2018/day14/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "day14" +version = "0.1.0" +authors = ["Andrew Coleman "] +edition = "2018" + +[dependencies] diff --git a/2018/day14/input b/2018/day14/input new file mode 100644 index 0000000..f8765c7 --- /dev/null +++ b/2018/day14/input @@ -0,0 +1 @@ +939601 diff --git a/2018/day14/src/main.rs b/2018/day14/src/main.rs new file mode 100644 index 0000000..d0e5cb7 --- /dev/null +++ b/2018/day14/src/main.rs @@ -0,0 +1,52 @@ +use std::fs::File; +use std::io::{BufRead, BufReader}; + +fn mutate_chocolate(scores: &mut Vec, recipes: i32) -> (String, usize) { + let mut elf1: usize = 0; + let mut elf2: usize = 1; + loop { + let elf1score = scores[elf1]; + let elf2score = scores[elf2]; + let sum = elf1score + elf2score; + let sum_str = format!("{}", sum); + for c in sum_str.chars() { + scores.push(c as u8 - 48); + } + + if scores.len() > recipes as usize + 100000000 { + break; + } + + elf1 = (elf1 + (1 + elf1score as usize)) % scores.len(); + elf2 = (elf2 + (1 + elf2score as usize)) % scores.len(); + } + + let mut result = String::new(); + for i in 0..10 { + result.push((scores[recipes as usize + i] + 48) as char); + } + + let mut score_str = String::with_capacity(scores.len()); + for s in scores.iter() { + score_str.push((s + 48) as char); + } + //println!("{}", score_str); + let recipe_str = format!("{}", recipes); + let recipe_index = score_str.find(recipe_str.as_str()).unwrap(); + + (result, recipe_index) +} + +fn main() { + let mut line = String::new(); + BufReader::new(File::open("input").unwrap()) + .read_line(&mut line) + .unwrap(); + let recipes = line.trim().parse::().unwrap(); + let mut scores: Vec = Vec::with_capacity(1000000); + scores.push(3); + scores.push(7); + let (final_score, final_index) = mutate_chocolate(&mut scores.clone(), recipes); + println!("part 1 final score {}", final_score); + println!("recipe repeated at index {}", final_index); +} From 28579c74874558cb3a3400c08618d1967acbfb0a Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Thu, 20 Dec 2018 13:09:06 -0500 Subject: [PATCH 3/3] cargo fmt --- 2018/day10/src/main.rs | 28 ++++++++++++++++++++-------- 2018/day11/src/main.rs | 14 +++++++++++--- 2018/day12/src/main.rs | 17 ++++++++++++++--- 2018/day13/src/main.rs | 29 ++++++++++++++++++----------- 2018/day14/src/main.rs | 1 - 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/2018/day10/src/main.rs b/2018/day10/src/main.rs index 9b07d67..485080f 100644 --- a/2018/day10/src/main.rs +++ b/2018/day10/src/main.rs @@ -11,7 +11,7 @@ struct Point { x: i32, y: i32, x_velocity: i32, - y_velocity: i32 + y_velocity: i32, } fn bounding_box(points: &Vec) -> (i32, i32, i32, i32) { @@ -21,10 +21,18 @@ fn bounding_box(points: &Vec) -> (i32, i32, i32, i32) { let mut max_y = std::i32::MIN; for p in points.iter() { - if min_x > p.x { min_x = p.x }; - if min_y > p.y { min_y = p.y }; - if max_x < p.x { max_x = p.x }; - if max_y < p.y { max_y = p.y }; + if min_x > p.x { + min_x = p.x + }; + if min_y > p.y { + min_y = p.y + }; + if max_x < p.x { + max_x = p.x + }; + if max_y < p.y { + max_y = p.y + }; } (min_x, min_y, max_x, max_y) @@ -55,7 +63,10 @@ fn tick(points: &mut Vec) -> i32 { } let (min_x, min_y, max_x, max_y) = bounding_box(points); - println!("final bounding box: ({}, {}) ({}, {})", min_x, min_y, max_x, max_y); + println!( + "final bounding box: ({}, {}) ({}, {})", + min_x, min_y, max_x, max_y + ); let mut final_set = HashSet::with_capacity(points.len()); for p in points.iter() { final_set.insert((p.x, p.y)); @@ -81,7 +92,8 @@ fn main() { .map(|line| line.unwrap()) .collect(); let mut points: Vec = Vec::with_capacity(lines.len()); - let re = Regex::new(r"^position=<([-| ]\d+), ([-| ]\d+)> velocity=<([-| ]\d), ([-| ]\d)>$").unwrap(); + let re = + Regex::new(r"^position=<([-| ]\d+), ([-| ]\d+)> velocity=<([-| ]\d), ([-| ]\d)>$").unwrap(); for line in lines.iter() { if re.is_match(line) { let cap = re.captures(line).unwrap(); @@ -93,7 +105,7 @@ fn main() { x, y, x_velocity, - y_velocity + y_velocity, }); } } diff --git a/2018/day11/src/main.rs b/2018/day11/src/main.rs index 7cd146a..12aeb4f 100644 --- a/2018/day11/src/main.rs +++ b/2018/day11/src/main.rs @@ -57,7 +57,9 @@ fn find_variable_max_sum(map: &[[i32; 300]; 300]) -> (usize, usize, i32, usize) let mut sum = 0; for i in 1..=300 { let (new_x, new_y, new_sum) = find_max_sum(map, i); - if new_sum == 0 { break; } + if new_sum == 0 { + break; + } if new_sum > sum { size = i; sum = new_sum; @@ -78,8 +80,14 @@ fn main() { let map = calc_map_from_serial_number(serial_number); let (x, y, sum) = find_max_sum(&map, 3); - println!("maximum sum coordinate of ({}, {}) with sum of {}", x, y, sum); + println!( + "maximum sum coordinate of ({}, {}) with sum of {}", + x, y, sum + ); let (x, y, sum, size) = find_variable_max_sum(&map); - println!("maximum variable sum found at ({}, {}) sum {} with size of {}", x, y, sum, size); + println!( + "maximum variable sum found at ({}, {}) sum {} with size of {}", + x, y, sum, size + ); } diff --git a/2018/day12/src/main.rs b/2018/day12/src/main.rs index 6dde003..a325f42 100644 --- a/2018/day12/src/main.rs +++ b/2018/day12/src/main.rs @@ -16,7 +16,11 @@ fn get_score(state: &[char; MAP_SIZE]) -> i64 { score } -fn run_game(initial_state: String, states: HashMap, generations: i64) -> (i64, [i64; MAP_SIZE]) { +fn run_game( + initial_state: String, + states: HashMap, + generations: i64, +) -> (i64, [i64; MAP_SIZE]) { let mut last_state = ['.'; MAP_SIZE]; for (i, c) in initial_state.char_indices() { if c == '#' { @@ -30,7 +34,7 @@ fn run_game(initial_state: String, states: HashMap, generations: i let mut next_state = ['.'; MAP_SIZE]; for i in 2..(MAP_SIZE - 2) { let mut key = String::new(); - for j in i-2..=i+2 { + for j in i - 2..=i + 2 { key.push(last_state[j]); } if let Some(dest_state) = states.get(&key) { @@ -53,7 +57,14 @@ fn find_big_score(initial_state: String, states: HashMap, iteratio if diff1 == diff2 { if diff2 == diff3 { let sum = ((iterations - i as i64 - 1) * diff1) + scores[i]; - println!("({} - {}) * {} + {} = {}", iterations - 1, i as i64, diff1, scores[i], sum); + println!( + "({} - {}) * {} + {} = {}", + iterations - 1, + i as i64, + diff1, + scores[i], + sum + ); return sum; } } diff --git a/2018/day13/src/main.rs b/2018/day13/src/main.rs index 2f37172..237c5e8 100644 --- a/2018/day13/src/main.rs +++ b/2018/day13/src/main.rs @@ -10,7 +10,7 @@ struct Cart { x_delta: i8, y_delta: i8, intersection: u8, - removed: bool + removed: bool, } impl Cart { @@ -60,7 +60,11 @@ impl Cart { } } -fn find_collision(map: &[[char; MAP_SIZE]; MAP_SIZE], carts: &mut Vec, find_last: bool) -> (usize, usize, u32) { +fn find_collision( + map: &[[char; MAP_SIZE]; MAP_SIZE], + carts: &mut Vec, + find_last: bool, +) -> (usize, usize, u32) { let mut ticks = 0; let cart_len = carts.len(); loop { @@ -97,20 +101,20 @@ fn find_collision(map: &[[char; MAP_SIZE]; MAP_SIZE], carts: &mut Vec, fin } else { carts[i].turn_left(); } - }, + } '\\' => { if carts[i].x_delta == 0 { carts[i].turn_left(); } else { carts[i].turn_right(); } - }, + } '+' => { carts[i].change_direction_at_intersection(); - }, + } ' ' => { panic!("off the rails!"); - }, + } _ => {} } carts[i].x = next_x; @@ -151,7 +155,7 @@ fn main() { x_delta: 0, y_delta: 1, intersection: 0, - removed: false + removed: false, }); map[j][line_number] = '|'; } else if c == '^' { @@ -161,7 +165,7 @@ fn main() { x_delta: 0, y_delta: -1, intersection: 0, - removed: false + removed: false, }); map[j][line_number] = '|'; } else if c == '<' { @@ -171,7 +175,7 @@ fn main() { x_delta: -1, y_delta: 0, intersection: 0, - removed: false + removed: false, }); map[j][line_number] = '-'; } else if c == '>' { @@ -181,7 +185,7 @@ fn main() { x_delta: 1, y_delta: 0, intersection: 0, - removed: false + removed: false, }); map[j][line_number] = '-'; } else { @@ -193,5 +197,8 @@ fn main() { let (x, y, ticks) = find_collision(&map, &mut carts.clone(), false); println!("found collision at {},{} after {} ticks", x, y, ticks); let (x, y, ticks) = find_collision(&map, &mut carts.clone(), true); - println!("found last remaining cart at {},{} after {} ticks", x, y, ticks); + println!( + "found last remaining cart at {},{} after {} ticks", + x, y, ticks + ); } diff --git a/2018/day14/src/main.rs b/2018/day14/src/main.rs index d0e5cb7..4abe52a 100644 --- a/2018/day14/src/main.rs +++ b/2018/day14/src/main.rs @@ -30,7 +30,6 @@ fn mutate_chocolate(scores: &mut Vec, recipes: i32) -> (String, usize) { for s in scores.iter() { score_str.push((s + 48) as char); } - //println!("{}", score_str); let recipe_str = format!("{}", recipes); let recipe_index = score_str.find(recipe_str.as_str()).unwrap();