adventofcode

2020-12-07T06:18:07.346100Z

Good morning 🙂

2020-12-07T06:18:48.346800Z

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

😂 3
😃 1
1
Aleks 2020-12-07T06:57:38.348600Z

might because it’s Monday 😁

fingertoe 2020-12-07T06:33:34.347700Z

This one seems quite a bit harder… 😉

imre 2020-12-07T07:58:58.349500Z

@imre has joined the channel

plexus 2020-12-07T08:08:44.350800Z

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.

✔️ 2
erwinrooijakkers 2020-12-07T08:18:29.352600Z

Under an hour you say? 😛

erwinrooijakkers 2020-12-07T08:18:49.352800Z

I’m lucky I still have time for breakfast

2020-12-07T08:28:41.353400Z

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

2020-12-07T08:30:12.354Z

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

2
Aleks 2020-12-07T08:32:56.355Z

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

2020-12-07T09:28:05.356300Z

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

😄 1
plexus 2020-12-07T09:37:57.358500Z

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

plexus 2020-12-07T09:38:07.358800Z

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

👍 4
🎉 5
plexus 2020-12-07T09:39:00.358900Z

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.

Aleks 2020-12-07T12:52:59.362Z

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

plexus 2020-12-07T13:21:33.362300Z

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

👍 2
erwinrooijakkers 2020-12-07T15:22:21.364Z

curious to what’s wrong? :_

erwinrooijakkers 2020-12-07T15:22:27.364200Z

have to stay tuned I guess

erwinrooijakkers 2020-12-07T15:22:39.364400Z

find out tomorrow in a new episode

2020-12-07T15:33:52.365900Z

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

2020-12-07T10:20:52.360500Z

@andrea.crotti has joined the channel

Pedro Sousa 2020-12-07T11:20:05.360900Z

@pedronsousa has joined the channel

tschady 2020-12-07T16:13:39.367600Z

Day 7 using graph library

tschady 2020-12-07T16:17:56.368300Z

and viz for fun:

🤯 2
Gerome 2020-12-07T19:11:42.369900Z

@gerome.bochmann has joined the channel

kenj 2020-12-07T19:19:35.370500Z

Somehow I managed a stack overflow using loop/`recur` 🤷‍♂️

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

kenj 2020-12-07T20:30:26.371700Z

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

tschady 2020-12-07T21:06:50.372400Z

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

markw 2020-12-07T21:14:23.372700Z

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

tschady 2020-12-07T21:15:50.372900Z

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

markw 2020-12-07T21:18:03.373100Z

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

markw 2020-12-07T21:18:12.373300Z

yikes formatting

markw 2020-12-07T21:24:17.373800Z

Nope

markw 2020-12-07T21:24:28.374Z

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

markw 2020-12-07T21:24:33.374200Z

it’s concat

tschady 2020-12-07T21:27:41.374600Z

cool, thanks for link

kenj 2020-12-07T21:55:18.374900Z

Thanks for taking a look!

kenj 2020-12-07T21:55:36.375100Z

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

kenj 2020-12-07T21:56:15.375300Z

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

plexus 2020-12-08T05:12:17.378Z

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.

plexus 2020-12-08T05:12:39.378200Z

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

👍 1
kenj 2020-12-07T20:31:41.372Z

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

brownfield 2020-12-07T22:36:01.375600Z

@shawnbrownfield has joined the channel