r/adventofcode • • Dec 13 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 13 Solutions -🎄-

--- Day 13: Mine Cart Madness ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 13

Transcript:

Elven chronomancy: for when you absolutely, positively have to ___.


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 00:44:25!

24 Upvotes

148 comments sorted by

View all comments

Show parent comment

2

u/jonathan_paulson Dec 13 '18 edited Dec 13 '18

Hmm...good point about modifying while iterating. I'm not actually sure what the semantics of that is...

The point of checking other.{r,c} against cart.{r,c} is to delete the current cart from the list (we want to delete two things)

Edit: A brief experiment suggests that it iterates over the original list, and reassigning to that variable has no effect. I think if I were modifying the list rather than creating a new one it would be worse. This makes some sense if you imagine for x in xs desugars into something like (I have no idea if this is true...)

it = iter(xs)
try:    
  while True:
    x = next(it)
    ..
 except StopIteration:
   ...

3

u/sophiebits Dec 13 '18

Right – you can have any arbitrary expression after "in", so it must continue to reference that value even after reassignment.