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. π
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/
looks like day3 part2 was a breaking point for lots of peeps
meaning number of devs gave up after that
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
ha, actually I just found out that today
after clicking next day willy nilly
damn this slack is a mess
usability sucks
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)
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
yeah, pleasant surprise! https://github.com/FelipeCortez/advent-of-code/blob/master/2021/10.clj
https://github.com/nbardiuk/adventofcode/blob/master/2021/src/day10.clj
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 +))
This day is confusing calvas syntax highlighting!
I like your substitutions! Need to introduce some in emacs.
I noticed i'm using remove a lot
switching to transients is pretty easy π
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))]))Lol => https://clojuredocs.org/clojure.core/pop#example-5a7e1ab7e4b0316c0f44f8b4
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!
Late to the party today.
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
https://github.com/tjefferson08/advent-of-code/blob/main/2021/10/core.clj
Tweaked mine a little, both solutions run in about 1ms in babashka
today's puzzle seemed relatively mundane, and so does my solution: https://github.com/euccastro/advent-of-code-2021/blob/main/day10.clj
https://gitlab.com/maximoburrito/advent2021/-/blob/main/src/day10/main.clj
https://github.com/zelark/AoC-2021/blob/main/src/zelark/aoc_2021/day_10.clj
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 :)
part 1 (inspired by @peterc)
Can somebody compare the performance of it to stack based implementation?