This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-10
Channels
- # adventofcode (54)
- # announcements (30)
- # asami (13)
- # aws (10)
- # babashka (16)
- # babashka-sci-dev (44)
- # beginners (95)
- # calva (63)
- # clara (10)
- # clj-kondo (3)
- # cljfx (6)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (68)
- # clojure-europe (59)
- # clojure-nl (7)
- # clojure-norway (12)
- # clojure-spec (6)
- # clojure-uk (6)
- # clojurescript (4)
- # component (4)
- # conjure (5)
- # datomic (3)
- # deps-new (1)
- # events (4)
- # exercism (1)
- # figwheel-main (1)
- # fulcro (33)
- # gratitude (1)
- # improve-getting-started (3)
- # jobs (3)
- # lsp (5)
- # malli (10)
- # membrane (5)
- # music (3)
- # nextjournal (6)
- # off-topic (42)
- # pedestal (2)
- # polylith (14)
- # portal (11)
- # re-frame (42)
- # releases (3)
- # reveal (4)
- # shadow-cljs (62)
- # tools-build (1)
- # tools-deps (3)
- # web-security (1)
- # xtdb (3)
I think I set a new land speed record for slowest possible code on Day 8 -> https://github.com/samedhi/advent-of-code-2021/blob/main/16.clj
🧵Day 10 answers thread: post your answers here
https://github.com/kconner/advent-of-code/blob/master/2021/10a.clj, https://github.com/kconner/advent-of-code/blob/master/2021/10b.clj. Feels good to me :)
https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2021/day10.clj
Day 10 Part 1
(def scores {\} 1197
\) 3
\] 57
\> 25137})
(defn parser [line]
(map identity line))
(defn find-syntax-error [opens [f & r]]
(if (empty? r)
nil
(cond (#{\{ \( \[ \<} f)
(recur (conj opens f) r)
(#{\} \) \] \>} f) ;
(if (= f (matching (peek opens)))
(recur (pop opens) r)
f))))
(->> (f/read-all-lines-and-parse "puzzle-inputs/2021/day10" parser)
(map (partial find-syntax-error []))
(remove nil?)
(map scores)
(reduce +))
I noticed i'm using remove a lot
hooray for reduced
https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2021/10.clj
Fun puzzle! https://github.com/RedPenguin101/aoc2021/blob/main/day10.md, and https://github.com/RedPenguin101/aoc2021/blob/main/clojure/src/aoc2021/day10.clj
This worked well for me:
(defn parse [l]
(loop [line l]
(let [new (-> line
(str/replace #"\[\]" "")
(str/replace #"\{\}" "")
(str/replace #"\<\>" "")
(str/replace #"\(\)" ""))]
(if (= (count new) (count line))
line
(recur new)))))
Same stack based approach. I didn’t flag the results, just used the fact that if a coll is returned, it’s the unbalanced stack, if it’s a single char it’s the bad one. https://github.com/tschady/advent-of-code/blob/main/src/aoc/2021/d10.clj
I wonder if he threw the <, >
in there just so you couldn’t use the clojure reader somehow
this is my regex approach
(defn fixed-point [f a]
(let [r (f a)]
(if (= r a)
a
(recur f r))))
(defn validate [line]
(let [fp (fixed-point #(string/replace % #"\(\)|\[\]|\{\}|\<\>" "") line)
invalid (re-find #"\)|\]|\}|\>" fp)]
[invalid (map open->close (string/reverse fp))]))
Well, that was a bit embarrasing how long it took to find the bug in (find-middle-score)
😖
Part 2
(def scores {\} 3
\) 1
\] 2
\> 4})
(def matcher {\{ \}
\[ \]
\< \>
\( \)})
(defn get-remaining [open [c & r]]
(if (nil? c)
open
(cond (#{\{ \[ \< \(} c)
(recur (conj open c) r)
(#{\} \] \> \)} c)
(if (= c (matcher (peek open)))
(recur (pop open) r)
nil))))
(defn score [auto-completes]
(reduce (fn [acc i]
(+ (* acc 5) (scores i))) 0 auto-completes))
(defn auto-complete [line]
(map matcher line))
(defn get-middle-score [scores]
(let [sorted-scores (sort scores)]
(nth sorted-scores (dec (Math/ceil (/ (count scores) 2.0))))))
(->> (f/read-all-lines-and-parse "puzzle-inputs/2021/day10" parser)
(map (partial get-remaining []))
(remove nil?)
(map auto-complete)
(map reverse)
(map score)
(get-middle-score))
I found very surprising that this works just fine (nth [1 2 3] (/ 3 2))
i think because this casts it to int
: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L894
pretty cool!
https://github.com/kfirmanty/advent-of-code-2021 found day10 to be much easier than few last ones. Will check other people solution but I guess most used list as stack to keep track of opened parens
My day 10: https://gist.github.com/borkdude/b5cf0e9d2d8ab7c678d88e27a3357b33#file-aoc21_d10-clj
today's puzzle seemed relatively mundane, and so does my solution: https://github.com/euccastro/advent-of-code-2021/blob/main/day10.clj
yeah, pleasant surprise! https://github.com/FelipeCortez/advent-of-code/blob/master/2021/10.clj
part 1 (inspired by @U1NLKFVC4)
Watch a script and run tests while developing with babashka. Should come in handy for Aoc :) https://github.com/babashka/babashka/discussions/1102
Very nice! I wonder if <> where valid bracket a clojure ide could solve it
Also could would be to see a regex solution
Hi, I just want to say that as a beginner in clojure, I've learnt so much from this thread and peoples answers. :thumbsup:
it has been breaking my brain a bit trying to decipher some of the solutions, but once I understand them I feel like I learned something new
If you like Clojure, and if you like Advent of Code, you might be interested in joining our remote Advent of Code meetup at Clojadelphia, next Thursday at 5pm EST. https://www.meetup.com/Clojadelphia/events/282565898/
i could honestly see that, i was frustrated (mainly with how it was worded/presented) with that one the most
I think a lot of people don't know that if you don't complete a day, you can still do the next
First time in my life I have written a double barreled recur statement -> https://github.com/samedhi/advent-of-code-2021/blob/main/18.clj (problem 9 second section)