This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (78)
- # announcements (12)
- # babashka (2)
- # beginners (116)
- # calva (20)
- # cider (17)
- # clj-kondo (15)
- # cljs-dev (51)
- # clojure (32)
- # clojure-android (1)
- # clojure-dev (4)
- # clojure-europe (91)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-spec (12)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (9)
- # conjure (3)
- # cryogen (4)
- # cursive (4)
- # data-science (1)
- # datomic (5)
- # depstar (5)
- # fulcro (39)
- # google-cloud (2)
- # kaocha (2)
- # malli (7)
- # off-topic (3)
- # pathom (3)
- # pedestal (5)
- # re-frame (19)
- # rewrite-clj (54)
- # ring (3)
- # shadow-cljs (12)
- # spacemacs (12)
- # specter (3)
- # tools-deps (63)
I was convinced that I was at my disadvantage, reading a very long text while having ADHD, but it turned out that I was not slower than others.
4.5 seconds on my computer, about half of anybody else’s computer. The code could me improved, I am sure.
Finally, a pair for which Clojure is wonderfully suited… https://github.com/rjray/advent-2020-clojure/blob/master/src/advent_of_code/day22.clj
ahh I didnt look at your code yet, my part-2 answer was chugging along, so its probably not correct
For me the bug was that I was finishing the round when seeing a repeated configuration, but it has to be the game. Which, if one thinks about it, makes much more sense.
This rules of avoiding repeating configuration is similar in the game of Go.
Mine runs in 4sec. But probably changing
double-queueshould improve that. I missed clojure's queues
Used queue for decks https://github.com/zelark/AoC-2020/blob/master/src/zelark/aoc_2020/day_22.clj
I avoided using a queue when I realized that it would not display its values in my REPL, I chose a vector instead.
I firstly went with vectors, but after the part 1 had been solved I changed my mind.
To be honest, they did scare me. Because last year at the same day was the hardest puzzle with a deck of cards as well.
@U1NLKFVC4 yeah i checked for that… I thought I had found the problem when I realized I misread the rules for how many cards to include in a subgame (which insidiously gave the correct answer on test input even with the bug). But I fixed that, and also verified the infinite loop case is handled.. and it’s still running. I’ll try again tomm
Today was even fun, I was afraid of complex combinatorics part 2 https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day22.clj
I should definitely look to queues ! Better performance and neater syntax.
around 250ms for part2 https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2020/day22.clj
today my daughter was definitely rooting for the crab!
my solution runs in
half a second 8-10sec (that's with me being lazy and using lists/sequences instead of vectors/queues)
https://github.com/euccastro/advent-of-code-2020/blob/master/src/advent/day22.clj runs in a little under 10s without memoization, so memoization seems to have a bigger impact on performance than picking the optimal data structures, and it only involves a one word change 🙂 wait, I lie... my solution takes 8-10 seconds. memoization made it finish in half a ms... the second time I run it! 😄. it's pretty useless because when we recur we take a different number of cards each time. I added memoization when I had missed that detail
@U076FM90B you seem to interpret that a game should end when the deck of either player has already been seen? https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day22.clj#L40
my interpretation is that the game ends only when both decks have been seen in a given round. it's curious that both approaches work?
> if there was a previous round in this game that had exactly the same cards in the same order in the same players' decks
I have trouble interpreting this statement. I guess it does not make a difference in the end because player 1 wins regardless of what deck is repeated
see where the apostrophe is placed. I think that basically means you bail if you see a previous game state again
seen deck of only one player is enough to end game, not both players' decks at the same time.
(or (seen1 deck1) (seen2 deck2))
(and (seen1 deck1) (seen2 deck2))
regardless, you might want to run
or option (as it terminates faster), and see whether you'll get a star
My solution https://github.com/benfle/advent-of-code-2020/blob/main/day22.clj
Why would you put this very important sentence in parenthesis 🙂 Wasted so much time.
(the quantity of cards copied is equal to the number on the card they drew to trigger the sub-game)
yes, I've just checked that the
or version works in my data, and runs in under 1/3 of the time
my interpretation is not even
(and (seen1 deck1) (seen2 deck2)), but an even stricter
(seen [deck1 deck2]) (e.g., bail out only if both decks have been seen together in the same turn)
yeah I implemented the stricter condition as well, though it is interesting to consider if the other player's deck will also be the same in the less strict case
I get the same result as well using the less restrictive case, and my time goes from ~8s to under 1s
I like this refactoring https://github.com/zelark/AoC-2020/commit/6894f49405522cde85b542ddfe923faa111ad80d
Also a good one 🙂 My first attempt to refact the function looked exactly the same.
iterate dec is a bit more natural for me here, cause there is no need for some extra numbers.
I must be learning from this experience, because my algorithm isn’t that much different than zelark’s (though I just used lists instead of queues or even vectors).
The funniest part of today’s puzzle is that the crab won the card game. Twice.
Must have been your data. For my data, I won the second game 🙂.
Yeah, you know what? We should celebrate on the last day of the AoC. How about a Post-AoC online meetup party?
I’m actually a bit stumped.. I track seen states, verified that on the test loop game, fixed the bug with taking
n cards in the subgames, works on sample, hangs forever on actual input
Only other thing I can think of is that the confusion around
or for seeing prior games. I interpreted that line as you need to see the entire game state (both decks) again
maybe post your current code? or try someone else's solution on your input data? to double check you haven't been given something broken
so bizarre.. so after changing to the interpretation of “seeing” a game as meaning either deck, it terminates… with the wrong answer. I’ll post what I’ve got, apologies for the mess as I’ve hacked it apart trying to fix it and it’s now pretty messy
probably something obvious that i’m just not getting, but it doesn’t help that the test input works perfectly, line-by line
I guess this condition in a wrong place
(if (= winner :player1) , the game should instantly end if there was a previous round in this game that had exactly the same cards.
Must have been your data. For my data, I won the second game 🙂.