diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:18:18 -0400 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:19:39 -0400 |
| commit | 87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch) | |
| tree | cd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/13/part1 | |
| parent | 1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff) | |
| download | aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip | |
Reorder days into src
Diffstat (limited to 'src/13/part1')
| -rw-r--r-- | src/13/part1 | 188 |
1 files changed, 188 insertions, 0 deletions
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 [1m[97mcarts[0m 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 [1m[97mcarts[0m 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 +[1m[97mleft[0m the first time, goes [1m[97mstraight[0m the second time, turns [1m[97mright[0m the third time, and then repeats +those directions starting again with [1m[97mleft[0m the fourth time, [1m[97mstraight[0m 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 [1m[97mcurrent location[0m: 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 +[1m[97mtick[0m. + +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 [1m[97mthe location of the first crash[0m. 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 [1m[97m7,3[0m. + + + + |
