Message Boards Message Boards

11
|
13556 Views
|
5 Replies
|
17 Total Likes
View groups...
Share
Share this post:

Advent of code 2020 solutions in Wolfram language

Posted 4 years ago

The Advent of Code challenge just finished for 2020. I did the first one five years ago or so. I was in the mood again this year. I've completed 46 of the 49 puzzles (2 per day). I think they've increased the difficulty some from what I remember, or my skills are deteriorating, haha. I've attached my solutions so far in the notebook.

The people who make the leaderboard are unbelievably fast at solving the puzzles, but one of the leaders posts his Python solutions after scoring is locked for the day, and I think several of my Wolfram solutions look structurally a bit more concise and clean in comparison. Although again, it's hard not to be impressed by how quickly the top 100 people solve the puzzles. They've often solved both parts of the day's puzzle before I finish reading the first part, haha.

Some highlights for me were using the built-in Chinese remainder theorem function for puzzle 13.2:

ChineseRemainder @@ 
 Transpose@
  MapIndexed[If[NumberQ@#, {-#2[[1]] + 1, #}, Nothing] &, 
   Import["input.txt", "CSV"][[2]]]

And solving 17.2 with the built in cellular automaton function with outer totalistic code 224 in 4 dimensions:

Count[CellularAutomaton[<|"OuterTotalisticCode" -> 224, 
   "Dimension" -> 
    4|>, {{{Characters@Import["input.txt", "List"] /. {"#" -> 1, 
       "." -> 0}}}, 0}, {{{6}}}], 1, \[Infinity]]

They actually had three days focused on cellular automata this year, which was pretty fun.

Anyway, I can't guarantee I'm going to get around to solving the last three puzzles, so I figured I'd go ahead and post what I had. Merry Christmas and happy holidays!

Attachments:
POSTED BY: Michael Hale
5 Replies

And for Q7, one can do nice visualizations (and analysis) using Graph operations such as Subgraph and GraphUnion, and options, such as GraphHighlight and VertexLabels. And the close integration of such functionality is, to me, what sets the Wolfram Language apart from the other programmatic solutions.

POSTED BY: Paul Abbott

My solution to Q1 used pattern-matching:

input /. {___,x_,___,y_,___,z_,___} /; x+y+z == 2020 :> x y z

which easily coped with the given input data.

POSTED BY: Paul Abbott
Posted 4 years ago

Another nice way of doing problem 1 is to use KnapsackSolve, which is a generalization of the subset-sum problem. For part 1.2, this ends up being quite a bit faster too.

Times@@Pick[nums, KnapsackSolve[({#, 1, 1} &)/@nums, {2020, 3}], 1]
POSTED BY: Tom M
Posted 4 years ago

That is a nice solution. And it would have been the required approach if they pushed the input size much beyond 200 numbers.

POSTED BY: Michael Hale

enter image description here -- you have earned Featured Contributor Badge enter image description here

Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract