This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (60)
- # aleph (2)
- # announcements (3)
- # architecture (2)
- # babashka (12)
- # beginners (90)
- # calva (14)
- # cider (32)
- # clj-kondo (1)
- # cljsrn (4)
- # cljtogether (7)
- # clojars (10)
- # clojure (161)
- # clojure-dev (110)
- # clojure-europe (58)
- # clojure-nl (3)
- # clojure-spec (35)
- # clojure-taiwan (1)
- # clojure-uk (24)
- # clojuredesign-podcast (3)
- # clojurescript (27)
- # conjure (47)
- # cursive (17)
- # data-science (1)
- # datomic (1)
- # depstar (6)
- # fulcro (20)
- # java (4)
- # jobs-rus (1)
- # luminus (4)
- # malli (10)
- # off-topic (8)
- # re-frame (4)
- # reagent (1)
- # reitit (9)
- # reveal (1)
- # rewrite-clj (8)
- # ring (3)
- # sci (44)
- # shadow-cljs (5)
- # spacemacs (6)
- # specter (8)
- # tools-deps (6)
- # vim (1)
- # xtdb (11)
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
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.
I got my 2 stars ^_^
. After I saw @U7PQH43PS finishing early, I decided to try again for another hour.
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 😛
I found my solution after running after the cat which kept interrupting me..
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 🙂
Solution to Day 21: https://github.com/benfle/advent-of-code-2020/blob/main/day21.clj
The only interesting bit is the use of the fixed-point method to identify the food containing each allergen.
@U067R559Q I like your solution, and I think that my extension of
group-by could have been useful to you in the
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
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
@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.
Maybe next year it will be part of the stdlib (I am kidding, that's impossible)
I feel silly having matched the parens of the "(contains ...)" part after seeing @U067R559Q just split with #"contains" and grab the words 🙂
the ingredients are probably randomly generated, they may also be spelled "contains".
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
@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.
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
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)?
similarly, @U8MJBRSR5, why are you coercing into a vector here: https://github.com/green-coder/advent-of-code-2020/blob/8b7814d5407a783e641b7b160e7672a12c4aa538/src/aoc/day_21.clj#L32 ?
(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
Just updated, now it got even simpler https://github.com/zelark/AoC-2020/commit/0f3b898fd1fce7b558239939814c941547e37b72#diff-81c48a0532316c42f7ff22c58f13917b8129fae2266d787458f41270948f4234
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.
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))