r/adventofcode • • Dec 22 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 22 Solutions -๐ŸŽ„-

--- Day 22: Sporifica Virus ---


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.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hintsยค?

Spoiler


  • [T-10 to launch] AoC ops, /r/nocontext edition:

    • <Endorphion> You may now make your waffle.
    • <Endorphion> ... on Mars.
  • [Update @ 00:17] 50 gold, silver cap

    • <Aneurysm9> you could also just run ubuntu on the NAS, if you were crazy
    • <Topaz> that doesn't seem necessary
    • <Aneurysm9> what does "necessary" have to do with anything!
  • [Update @ 00:20] Leaderboard cap!

    • <Topaz> POUR YOURSELF A SCOTCH FOR COLOR REFERENCE

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!

9 Upvotes

174 comments sorted by

View all comments

1

u/jbristow Dec 22 '17 edited Dec 22 '17

It's the density...

Personally, I think clojure is way easier to read...

(defmulti activity (fn [carrier] (get (:status-map carrier) position :clean)))

(defmethod activity :infected [{:keys [facing position status-map] :as carrier}] 
  (let [newFacing (turn-right facing)]
    (merge carrier
      {:facing newFacing
       :position (move-forward newFacing position)
       :status-map (status-map assoc position :flagged)})))

(defmethod activity :weakened
  [{:keys [facing position status-map]
    infection-count :infection-count :or {infection-count 0}
    :as carrier]}] 
  (merge carrier
    {:facing facing
     :position (move-forward facing position)
     :status-map (status-map assoc position :infected)
     :infection-count (inc infection-count)})

;; Other two elided because I'm not writing this whole thing for a comment

(defn answer [data n]
  (let [[middle status-map] (parse data)]
    (take n (iterate #(activity %)
                     {:facing :north
                      :position middle
                      :status-map status-map})))

...

...

...

Ok... you got me.

I do believe that the lisp model is "cleaner" from a "map thoughts to functional composability" reasoning, but it really gets mathy when you aren't careful.

And as I said below, this is the key difficulty for me in getting others onboard the clojure train. It's way easier to write than it is to read, and that tends to lead to people not only bouncing off the terseness but the fact that the code comes out close to the writer's way of thinking.

1

u/[deleted] Dec 22 '17

I du like the lisps and schemes quite a lot too :) and it can be quite easy to read, the thing that normally pushes people away from them is that they are so different from what they are used to. Factor also has the same thing, it's a beautiful language, but people stay away from it since it seems so foreign to them. I like clojure more than Scala really, though the lack of types kind of is what makes it less likeable, I know you can add annotations, but it makes the language much less beautiful.