r/adventofcode • • Dec 18 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 18 Solutions -🎄-

--- Day 18: Settlers of The North Pole ---


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 18

Transcript:

The best way to avoid a minecart collision is ___.


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:21:59!

9 Upvotes

126 comments sorted by

View all comments

Show parent comment

1

u/wjholden Dec 18 '18

Mathematica

Nice, very compact. I like the idea of assigning characters a numeric value; I kept with using strings.

What is the /. operator you used on the import line?

2

u/[deleted] Dec 18 '18

That's ReplaceAll. One of Mathematica's strengths is this sort of "term rewriting." I'm sure you've noticed that many major functions like Solve[] return their responses in the form of these rewrite rules, e.g. {x->3,y->2}, you can use those to rewrite the terms in any expression. x^2+x+1 /. {x->3,y->2} for example.

2

u/wjholden Dec 18 '18

I will have to learn more about this. Thank you!

1

u/[deleted] Dec 23 '18

Forgot to mention, the only reason for giving them a numeric value was to work ArrayPlot.