Part 1: Load a minecart track that looks like this:
/->-\
| | /—-
| /-+–+-\ |
| | | | v |
-+-/ -+–/
-—–/
> Assuming minecarts follow the tracks and alternate turning left, going straight, and turning right on each intersection (`+`), where does the first collision occur?
> NOTE: Update carts top to bottom, left to right. Carts can collide mid update.
Okay. It's an interesting data format problem mostly. And we have to deal a bit with not being imperative, in particular when we're doing the updates, since having collisions happen halfway through an update is not so great. Let's load it:
```racket
(struct point (x y) #:transparent)
(struct cart (location velocity next-turn) #:transparent)
(struct track (data carts top-left bottom-right) #:transparent)
The goal will be to load the tracks into a hash of point
to character (so I know how the track turns / intersects) and separately store the carts. I’ll want to process the track after the initial load to replace carts with their underlying track and get the initial velocity as well. Finally, next-turn
will always start as 'left
, but we’ll deal with that later.
read more...