adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
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
fingertoe 2020-12-07T06:33:34.347700Z

This one seems quite a bit harder… 😉

2020-12-07T06:42:32.347800Z

I need to improve my regex capture skills. Let me know if you have a fast way to do the parsing/capturing, I am interested to learn.

2020-12-07T06:43:24.348Z

split keyboard? 😉

Narve Saetre 2020-12-07T06:44:08.348200Z

yeah, I c your point. I can also use minor (-> or (->> lines within the larger thread-block as well. Just gotta pick the right tool for the job 🙂

2020-12-07T06:55:56.348400Z

not ideal, but I came up with this for parsing

(defn parse-entry [entry]
  (let [p  (re-find #"\w+ \w+" entry)
        cs (->> (re-seq #"(\d+) (\w+ \w+)" entry)
                (reduce (fn [m [_ v k]] (assoc m k (Long/parseLong v))) {}))]
    [p cs]))

(def bags (into {} (map parse-entry (str/split-lines input))))

2020-12-07T06:57:38.348600Z

might because it’s Monday 😁

2020-12-07T07:41:34.348800Z

I just realized that the algorithm for part2 could be used for part1

oxalorg (Mitesh) 2020-12-07T07:56:35.349100Z

My naive solution: https://github.com/oxalorg/aoc/blob/main/src/puzzle7.clj Using some kind of memo could speed up first pass, but this works! ^_^

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

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

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

Day 7 using graph library

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

and viz for fun:

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

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

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

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

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

tws 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

tws 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

tws 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