Fork me on GitHub
Vincent Cantin05:12:10

Day 21 answers thread - Post your answers here

Vincent Cantin05:12:10

Day 21 answers thread - Post your answers here

Daw-Ran Liou06:12:43

For part 2, I just need to clean up the data a bit to figure out the answer manually πŸ˜›

πŸŽ‰ 5
πŸ‘ 1
Vincent Cantin06:12:18

wow ! you are fast

Vincent Cantin06:12:34

I didn’t do the part 1 yet

Daw-Ran Liou06:12:53

I’m sure I can clean up the logic more but it is what it is… Now time to go back to my day 20 lol.

Vincent Cantin06:12:22

I got my 2 stars ^_^ .Β  After I sawΒ @U7PQH43PSΒ finishing early, I decided to try again for another hour.

πŸ‘ 2

@U8MJBRSR5 Love your solution for part 1 πŸ˜„


So simple but it works like a charm

😊 1

(yeah, I finally woke up early-ish and couldn't resist giving it a try)


I was already looking into core.logic for the first part when my daughter woke up and the solution popped up in my mind while putting her to sleep again πŸ˜›


can't overemphasize the value of stepping away from the computer sometimes

βž• 4
Vincent Cantin08:12:41

I found my solution after running after the cat which kept interrupting me..

🐱 1

@U076FM90B need a util function for pruning already, yeah.

πŸ’― 1
Max Deineko12:12:34

One from a newcomer to both clojure and aoc: Not in leaderboard or racing mode, there's definitely lots to learn from the solutions here for me πŸ™‚

πŸ‘ 3

This one was more reasonable than yesterday πŸ™‚

βž• 2

The only interesting bit is the use of the fixed-point method to identify the food containing each allergen.

Vincent Cantin12:12:17

@U067R559Q I like your solution, and I think that my extension of group-by could have been useful to you in the parse-input function.

πŸ™ 1

Nice one @U067R559Q. A lot of work is done in the parsing function :)

πŸ™ 1

I need to improve my parsing/regexp game.


> newcomer to both clojure and aoc @

[clojure.algo.generic.functor :refer [fmap]]

Max Deineko13:12:37

@U051HUZLD is fmap something arcane or comes with some caveats? iirc I stumbled upon it at the very beginning of my looking at clojure while searching for a predefined way to transform a map's keys -- it seemed to me like something which would be a natural part of the standard library


have not seen it used in 5 years, but it looks useful. I think it is not a part of a stdlib because of transducers, and you very rarely just "map f over things and that's it". More often you then filter/remove/etc. over it, and only then pick a container for a result. @U9TGHG3LP

πŸ“Ž 1

re-pouring the map result into specific container after each step of a transformation is like anti-transducer, and it is useful only for a single step mapping

πŸ’‘ 1

@U8MJBRSR5 thank you. Yes, it could. πŸ™‚ But I want to keep every solution as and independent one and relying only clojure stdlib and java interop sometimes. Maybe next year I’ll pick a different way.

Vincent Cantin15:12:20

Maybe next year it will be part of the stdlib (I am kidding, that's impossible)

πŸ˜ƒ 1

I feel silly having matched the parens of the "(contains ...)" part after seeing @U067R559Q just split with #"contains" and grab the words πŸ™‚

βž• 1
Vincent Cantin17:12:46

It's ok to be paranoid .. don't worry.

Vincent Cantin17:12:20

the ingredients are probably randomly generated, they may also be spelled "contains".

Vincent Cantin17:12:00

For the same reason, I won't use read-string but edn/read-string


one trick that seems to recurrently work in aoc challenges is to resolve constraints by sorting the entries by length at the beginning and assuming that the earlier ones will always be the first ones to resolve


I guess that would be more robust if you sorted on every iteration (but then it would be no more efficient or pretty than searching for the already resolved items explicitly)


separating the allergens into their own entries from the beginning is a nice touch, @U067R559Q. I wouldn't have guessed that it would simplify things that much later on


i.e., as opposed to keeping allergen sets by line


@U65FN6WL9 I’m glad you learned something from my code, I think that’s one reason why we all here. I always learn something new from other’s solutions.

βž• 1

Last year I solved puzzles solely and wasn’t in this chat. I regret a bit about it.


yeah I only started solving the puzzles (after having binge watched @U07FP7QJ0's videos) so I would be better primed to understand others' solutions


I'm still mulling on (reduce into []) πŸ˜„


so that would be like concat into a vector? but wouldn't frequencies work the same had you concatenated them before by using mapcat instead in (map (comp val first) foods)?


(my own solution needs some cleanup, I'm just making sure I'm not missing something subtle)


> but wouldn’tΒ `frequencies`Β work the same had you concatenated them before by usingΒ `mapcat` Actually, yes. Thank you for pointing out!


yw! another thing I don't fully understand is why do you invert the result map in narrow . it shouldn't matter since it's a 1:1 mapping. if you kept allergens as keys then you could use plain sort instead of (sort-by val) (then you'd need to (map second) , but that's no worse than (map first) I guess? but the main point to me is that it's a bit surprising that `narrow' inverts, on top of narrowing


It was originally built for day 16, over there it makes more sense than here.

Vincent Cantin18:12:20

The code on github is mainly what I wrote while running against the clock. The vec was not needed, but when I typed it I didn't know yet. I favor vectors over sequences because of the constant access time and fast subvec.

πŸ‘ 1

@U65FN6WL9 thank you for the code review ^_^

πŸ‘ 1
Vincent Cantin18:12:35

4 days to go !

tree-shake 5
🌲 3
πŸŽ„ 3
⭐ 1

Tried some Common Lisp for today, spent really long time debugging. The problem was that mapcan was doing some sideffect and modifying my list, something that would have never happend with mapcat , I still don't quite understand why, but I had to switch (mapcan #'f xs) to (apply #'concatenate 'list (mapcar #'f xs))

Vincent Cantin07:12:43

I would love to join the conversation, but I don’t know CL - sorry.