Fork me on GitHub
#adventofcode
<
2020-12-07
>
Vincent Cantin06:12:07

Good morning 🙂

Vincent Cantin06:12:48

“Oh oh oh” (to read with the voice of Santa Claus) … it seems that the channel is more quiet than usual 😉

😃 3
😂 9
trollface 3
alekszelark06:12:38

might because it’s Monday 😁

fingertoe06:12:34

This one seems quite a bit harder… 😉

plexus08:12:44

Today's was definitely harder than the last few days, but not too hard yet. I quite like them like this. A bit challenging but still solvable in under an hour.

✔️ 6
erwinrooijakkers08:12:29

Under an hour you say? 😛

erwinrooijakkers08:12:49

I’m lucky I still have time for breakfast

Vincent Cantin08:12:41

I am going to add Specter and Instaparse to my deps.edn

Vincent Cantin08:12:12

Instaparse has a good API for parsing and shaping the result data.

gotta_go_fast 6
alekszelark08:12:56

I’m going to stack with vanilla Clojure for this AoC

Stuart09:12:05

I just woke up, looked at it, it's not a 9am problem.

😄 3
plexus09:12:57

yeah I'm also generally sticking to vanilla clojure, unless I really end up re-implementing a common library

plexus09:12:07

today's video: https://youtu.be/uujzvDnEXp0

🎉 15
👍 12
plexus09:12:00

and solution: https://github.com/lambdaisland/aoc_2020/blob/main/src/lambdaisland/aoc_2020/puzzle07.clj I also talk a bit more about yesterday's puzzle, and answer some questions people asked in the comments.

alekszelark12:12:59

maybe I missed it, have you mentioned that using io/reader without with-open macro is not a good practice?

plexus13:12:33

Oh that's a good point, I'll mention it tomorrow

👍 6
erwinrooijakkers15:12:21

curious to what’s wrong? :_

erwinrooijakkers15:12:27

have to stay tuned I guess

erwinrooijakkers15:12:39

find out tomorrow in a new episode

Stuart15:12:52

I think its because if you call io/reader without with-open (or explicitly try / catch yourself), then you can be left with an open reader in the case of an exception? But I'm guessing here. If thereis an exception I think with-open calls close on its binding

tws16:12:39

Day 7 using graph library

tws16:12:56

and viz for fun:

🤯 6
kenj19:12:35

Somehow I managed a stack overflow using loop/`recur` :man-shrugging:

(count (bag-children "shiny gold" sample-bags))
=> 32
(count (bag-children "shiny gold" bags))
Execution error (StackOverflowError) at (REPL:1).

kenj20:12:26

Can anyone help me figure out my stack overflow issue? I realize my code/approach is far from optimal… all the same it bugs me I can’t reason about why this is failing the way it is https://gist.github.com/KennyMonster/4e965505f0a8b592a91dd25b5306023f

tws21:12:50

you have a recursive call inside a recur form, that’s atypical

markw21:12:23

i don’t think he does.. he shadowed bag children in the loop binding

tws21:12:50

oops, missed. I guess that’s a reason to avoid that.

markw21:12:03

(defn bag-children [color bags] (let [bags-lookup (into {} (map #(vector (:color %) %) bags))] (loop [colors-to-walk [color] bag-children []] (if (seq colors-to-walk) (let [contained-bags (mapcat contained-bag-colors-as-seq (:contain (bags-lookup (first colors-to-walk))))] (recur (into (subvec colors-to-walk 1) contained-bags) (into bag-children contained-bags))) bag-children))))

markw21:12:12

yikes formatting

markw21:12:28

I edited his gist since I can’t format in slack apparently

markw21:12:33

it’s concat

tws21:12:41

cool, thanks for link

kenj21:12:18

Thanks for taking a look!

kenj21:12:36

I had no idea about concat… I had just assumed it was lazy

kenj21:12:15

or that even if it was eager, it would just utilize too much memory vs a stack overflow

plexus05:12:17

it is lazy, which is why you're getting the stack overflow. consider this

(def x (reduce concat (map #(list %) (range 100000))))

(first x)
the def will work fine, but as soon as you try to realize the first element it throws. At that point it tries to realize the outer concat, which first needs to realize the concat inside of it, and so forth until it bottoms out. Realizing a lazy-seq concumes a stack frame. It's really just a wrapper around an IFn which implements the Seq interface.

plexus05:12:39

I'll talk about this on the stream today, it's one of those surprising clojure gotchas.

👍 3
kenj20:12:41

I would think my part 2 solution would just take a ton of time/memory