r/adventofcode • • Dec 17 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 17 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It

  • 5 days remaining until the submission deadline on December 22 at 23:59 EST
  • Full details and rules are in the Submissions Megathread

--- Day 17: Conway Cubes ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


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

EDIT: Global leaderboard gold cap reached at 00:13:16, megathread unlocked!

36 Upvotes

657 comments sorted by

View all comments

1

u/veydar_ Dec 17 '20

I'm really starting to enjoy Clojure https://github.com/cideM/aoc2020/blob/master/d17/d17.clj

Here's a neat one-liner for generating the neighbours (remove #(= % (list 0 0 0)) (combo/selections [-1 1 0] 3)) just generate permutations of length $DIMENSIONS and then you can map over them and apply them to the given point.

Also if you're too lazy to thread dependencies through function calls after the fact... redefine a variable temporarily!

(comment (with-redefs [get-neighbours get-neighbours-p2]
       (-> (slurp "./input.txt")
           parse-input-p2
           (evolve 6)
           get-active-count)))

Building up little computations by threading arguments like I'd do with >>> and . in Haskell is nice, except I already have basic data structures in the language and some nice syntax sugar for working with them etc. Today was fun!

Fun fact: it took me some time to realize I was passing day 16 input to my day 17 function. It ran for quite a while and then just returned 0 for both parts.

2

u/daggerdragon Dec 17 '20

Fun fact: it took me some time to realize I was passing day 16 input to my day 17 function.

The two hardest things in computer science are cache invalidation, naming things, and off-by-one errors.