Fork me on GitHub
#adventofcode
<
2020-12-21
>
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 πŸ˜› https://github.com/dawranliou/advent-of-code/blob/master/2020/src/dawranliou/advent_of_code_2020/day_21.clj

πŸŽ‰ 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
peterc08:12:11

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

peterc08:12:25

So simple but it works like a charm

😊 1
euccastro08:12:00

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

euccastro08:12:20

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 πŸ˜›

euccastro08:12:14

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
misha11:12:42

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

πŸ’― 1
Max Deineko12:12:34

One from a newcomer to both clojure and aoc: https://github.com/next-mad-hatter/adventofcode/blob/master/src/aoc_2020/day_21.clj Not in leaderboard or racing mode, there's definitely lots to learn from the solutions here for me πŸ™‚

πŸ‘ 3
benoit12:12:23

This one was more reasonable than yesterday πŸ™‚

βž• 2
benoit12:12:27

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
benoit12:12:41

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

πŸ™ 1
benoit13:12:05

I need to improve my parsing/regexp game.

misha13:12:36

> newcomer to both clojure and aoc @

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

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

misha13:12:51

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
misha13:12:00

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
alekszelark14:12:41

@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
euccastro17:12:27

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

euccastro17:12:20

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

euccastro17:12:30

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)

euccastro17:12:47

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

euccastro17:12:22

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

alekszelark17:12:16

@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
alekszelark17:12:46

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

euccastro17:12:45

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

euccastro17:12:57

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

euccastro17:12:39

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

euccastro17:12:21

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

alekszelark17:12:36

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

euccastro17:12:46

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

alekszelark18:12:19

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
alekszelark18:12:24

@U65FN6WL9 thank you for the code review ^_^

πŸ‘ 1
Vincent Cantin18:12:35

4 days to go !

tree-shake 5
🌲 3
πŸŽ„ 3
⭐ 1
1
Average-user18:12:26

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.