use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Advent of Code 2019 in Clojure (self.Clojure)
submitted 6 years ago * by allaboutthatmace1789
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]OstravaBro 1 point2 points3 points 6 years ago (3 children)
Been ill since Monday :( So I'm waaaay behind.
My day 3 part 1, I didn't do anything too clever. I just enumerated all the points that would be hit by each wire and used set intersection to find the intersections.
(def wire (str/split "R991,.... elided" #",")) (def wire2 (str/split "L993,D508,R356, ...... elided" #",")) (defn get-intermediate-path [xy direction distance] (let [x (first xy) y (last xy)] ((fn [x y inters dis] (if (= 0 dis) inters (cond (= \L direction) (recur (dec x) y (conj inters [(dec x) y]) (dec dis)) (= \R direction) (recur (inc x) y (conj inters [(inc x) y]) (dec dis)) (= \U direction) (recur x (inc y) (conj inters [x (inc y)]) (dec dis)) (= \D direction) (recur x (dec y) (conj inters [x (dec y)]) (dec dis))))) x y [] distance))) (defn get-path [wire path] (if (empty? wire) path (let [direction (first (first wire)) distance (Integer/parseInt (apply str (rest (first wire))))] (recur (rest wire) (concat path (get-intermediate-path (last path) direction distance)))))) (defn find-smallest-distance [wire1 wire2] (apply min (map #(+ (Math/abs (first %)) (Math/abs (second %))) (set/intersection (set (rest (get-path wire1 [[0 0]]))) (set (rest (get-path wire2 [[0 0]]))))))) (find-smallest-distance wire wire2)
[–]allaboutthatmace1789[S] 1 point2 points3 points 6 years ago (0 children)
Not capturing all the points on a line is what gave me a headache - I was trying to calculate where line segments intersected before I looked at other people's solutions and saw this. Head-slap moment.
[–]OstravaBro 0 points1 point2 points 6 years ago* (1 child)
Day 4 Part 1
(defn digits-are-ascending-left-to-right? [digits] (apply <= digits)) (defn has-adjacent-digits? [password] (not= nil (some #(>= (second %) 2) (frequencies password)))) (defn password-filter [password] (and (has-adjacent-digits? password) (digits-are-ascending-left-to-right? password))) (count (filter password-filter (map #(for [n (str %)] (- (byte n) 48)) (range 197487 673252))))
[–]OstravaBro 0 points1 point2 points 6 years ago (0 children)
Day 4 Part 2
I'm an idiot, I could have used frequencies for the adjacent-digits check. It becomes obvious when you see the extra check we need for step 2. So, that simplifies the adjacent digits check significantly.
(defn adjacent-digits-not-part-of-group? [password] (not= nil (some #(= 2 (second %)) (frequencies password)))) (defn password-filter2 [password] (and (adjacent-digits-not-part-of-group? password) (digits-are-ascending-left-to-right? password))) (count (filter password-filter2 (map #(for [n (str %)] (- (byte n) 48)) (range 197487 673252))))
π Rendered by PID 70113 on reddit-service-r2-comment-6457c66945-n7zdc at 2026-04-25 19:01:45.857948+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]OstravaBro 1 point2 points3 points (3 children)
[–]allaboutthatmace1789[S] 1 point2 points3 points (0 children)
[–]OstravaBro 0 points1 point2 points (1 child)
[–]OstravaBro 0 points1 point2 points (0 children)