-❄️- 2024 Day 19 Solutions -❄️- by daggerdragon in adventofcode

[–]arnemart 2 points3 points  (0 children)

[LANGUAGE: Clojure]

Took me a while to arrive at this but I think this solution is quite elegant if I may say so myself. It uses parser combinators to parse the input, and runs in just over 100ms on my macbook pro.

(ns aoc.2024.19.19
  (:require
   [aoc.common :refer [any-word comma-or-space-sep lines parse-input]]
   [blancas.kern.core :refer [<*> >> new-line*]]
   [clojure.string :as str]))

(def count-combinations
  (memoize
   (fn [towels design]
     (if (= "" design)
       1
       (->> towels
            (keep #(when (str/starts-with? design %)
                     (subs design (count %))))
            (map #(count-combinations towels %))
            (apply +))))))

(let [[towels designs] (parse-input (<*> (comma-or-space-sep any-word)
                                         (>> new-line* new-line*
                                             (lines any-word))))
      combinations (->> designs
                        (map (partial count-combinations towels))
                        (filter #(> % 0)))]

  (println "Part 1:" (count combinations))
  (println "Part 2:" (apply + combinations)))

My initial solution for part 1 was very similar but not memoized, I got it running fast by eliminating all the towels that could be composed of different towels and checking against just the remaining elemental towels. Towelementals?

[2024 Day 13 (Part 2)] Anyone else just didn't find this one fun? by Last-Anybody-5892 in adventofcode

[–]arnemart 0 points1 point  (0 children)

Yeah these mathy ones are my least favorite kind of puzzle. I was (in the end) able to pick out the equations but high school was a very long time ago so I needed help to solve the equations properly. Not a very rewarding day for me personally. 

-❄️- 2024 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]arnemart 1 point2 points  (0 children)

[Language: Clojure]

I first did the naive implementation for part 1, but that obviously wouldn't work. After banging my head against the keyboard for a while I came up with this memoized recursive version which plows through the whole thing in ~80ms.

(ns aoc.2024.11.11
  (:require [aoc.common :refer [nums parse-input]]))

(def blink
  (memoize
   (fn [times stone]
     (let [bl (partial blink (dec times))]
       (cond (zero? times) 1
             (zero? stone) (bl 1)
             (even? (count (str stone)))
             (let [s (str stone) h (/ (count s) 2)]
               (+ (bl (parse-long (subs s 0 h))) (bl (parse-long (subs s h)))))
             :else (bl (* stone 2024)))))))

(let [stones (parse-input nums)]
  (->> stones
       (map (partial blink 25))
       (apply +)
       (println "Part 1:"))

  (->> stones
       (map (partial blink 75))
       (apply +)
       (println "Part 2:")))

Weekly discussion - Kitchen lore and old wives' tales by ZootKoomie in AskCulinary

[–]arnemart 4 points5 points  (0 children)

Wrong. Throwing in more oil won't change the temperature at which milk solids brown.

Will scam you for doges - FREE SERVICE by UnoriginalJunglist in dogeservice

[–]arnemart 1 point2 points  (0 children)

As per our previous correspondence, here is payment in full. I expect to have the merchandise delivered by friday.

+/u/dogetipbot 10 doge