adventofcode

borkdude 2021-12-10T08:20:04.009400Z

Watch a script and run tests while developing with babashka. Should come in handy for Aoc :) https://github.com/babashka/babashka/discussions/1102

1
nbardiuk 2021-12-10T10:44:24.011800Z

πŸ‘ 7
2
3
3
6
Antonio Bibiano 2021-12-10T11:17:01.016Z

Very nice! I wonder if <> where valid bracket a clojure ide could solve it

Antonio Bibiano 2021-12-10T11:17:31.016700Z

Also could would be to see a regex solution

zxspectrr 2021-12-10T12:13:07.018300Z

Hi, I just want to say that as a beginner in clojure, I've learnt so much from this thread and peoples answers. πŸ‘

5
❀️ 6
🌹 1
zxspectrr 2021-12-10T12:14:05.019200Z

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

Nick McAvoy 2021-12-10T16:28:24.024400Z

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/

Sidestep 2021-12-10T17:10:02.026700Z

looks like day3 part2 was a breaking point for lots of peeps

Sidestep 2021-12-10T17:10:46.027600Z

meaning number of devs gave up after that

Sidestep 2021-12-10T17:10:48.027800Z

https://adventofcode.com/2021/stats

πŸ“‰ 1
Darin Douglass 2021-12-10T17:16:32.028400Z

i could honestly see that, i was frustrated (mainly with how it was worded/presented) with that one the most

2021-12-10T17:17:11.028800Z

I think a lot of people don't know that if you don't complete a day, you can still do the next

Sidestep 2021-12-10T17:17:56.029200Z

ha, actually I just found out that today

Sidestep 2021-12-10T17:18:10.029600Z

after clicking next day willy nilly

Sidestep 2021-12-10T17:30:24.030900Z

damn this slack is a mess

Sidestep 2021-12-10T17:30:32.031200Z

usability sucks

samedhi 2021-12-10T23:58:53.038Z

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)

samedhi 2021-12-10T04:33:57.006500Z

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

Aleks 2021-12-10T04:59:24.007300Z

🧡Day 10 answers thread: post your answers here

Felipe 2021-12-11T18:20:27.055800Z

yeah, pleasant surprise! https://github.com/FelipeCortez/advent-of-code/blob/master/2021/10.clj

2021-12-10T09:03:42.010200Z

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 +))

2021-12-10T09:04:24.010400Z

This day is confusing calvas syntax highlighting!

πŸ€ͺ 3
genmeblog 2021-12-10T09:24:47.010900Z

I like your substitutions! Need to introduce some in emacs.

Antonio Bibiano 2021-12-10T10:31:07.011100Z

Antonio Bibiano 2021-12-10T10:32:27.011600Z

I noticed i'm using remove a lot

2021-12-10T11:07:07.013400Z

2021-12-10T11:16:14.014900Z

switching to transients is pretty easy πŸ‘Œ

Callum Oakley 2021-12-10T11:24:24.016800Z

hooray for reduced https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2021/10.clj

peterc 2021-12-10T13:14:53.020100Z

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)))))

πŸ’― 1
πŸ†’ 4
tschady 2021-12-10T13:38:20.021Z

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

tschady 2021-12-10T14:16:33.021700Z

I wonder if he threw the <, > in there just so you couldn’t use the clojure reader somehow

Antonio Bibiano 2021-12-10T14:23:18.022Z

this is my regex approach

Antonio Bibiano 2021-12-10T14:23:21.022200Z

(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))]))

J 2021-12-10T16:39:22.025300Z

Lol => https://clojuredocs.org/clojure.core/pop#example-5a7e1ab7e4b0316c0f44f8b4

πŸ˜‚ 3
πŸ˜† 1
2021-12-10T17:05:34.026100Z

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))

Antonio Bibiano 2021-12-10T18:38:18.033200Z

I found very surprising that this works just fine (nth [1 2 3] (/ 3 2))

tschady 2021-12-10T18:56:14.033500Z

i think because this casts it to int: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L894

Antonio Bibiano 2021-12-10T19:05:07.033800Z

pretty cool!

mchampine 2021-12-10T19:44:54.034200Z

Late to the party today.

2021-12-10T19:49:09.034600Z

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

borkdude 2021-12-10T22:29:31.036400Z

Tweaked mine a little, both solutions run in about 1ms in babashka

1
🐎 1
euccastro 2021-12-10T23:01:03.036800Z

today's puzzle seemed relatively mundane, and so does my solution: https://github.com/euccastro/advent-of-code-2021/blob/main/day10.clj

Fredrik 2021-12-10T05:26:18.007600Z

Sidestep 2021-12-14T20:29:50.123100Z

part 1 (inspired by @peterc)

Sidestep 2021-12-14T20:31:35.123500Z

Can somebody compare the performance of it to stack based implementation?