tonight’s puzzle… reading comprehension
On this one, I miss a detail which costs me at least 20 minutes. 😄
Day 22 answers thread - Post your answers here
Just the part 1 so far: https://github.com/dawranliou/advent-of-code/blob/master/2020/src/dawranliou/advent_of_code_2020/day_22.clj
630ms https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/y2020/day22.cljc#L11
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
@nbardiuk 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
if any of the player has been seen game stops
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
yes, but maybe player 2 would have won if the game hadn't been aborted?
(obvs. that isn't happening in your input, so who knows)
seen deck of only one player is enough to end game, not both players' decks at the same time.
(or (seen1 deck1) (seen2 deck2))
not
(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)
my interpretation is the same
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
Why not using range
?
https://github.com/green-coder/advent-of-code-2020/blob/b1f99617fa9587fc1269c4eac5fc2adfd2a536b0/src/aoc/day_22.clj#L53
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).
https://github.com/green-coder/advent-of-code-2020/blob/master/src/aoc/day_22.clj
Nice! What was the run time for part2 for you?
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
Pretty sure I can get that shorter. Tomorrow.
Also, the title of this thread is “Day 21 answers…” 🙂.
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.
ahh I didnt look at your code yet, my part-2 answer was chugging along, so its probably not correct
waiting for part 2 to finish.. must have bug somewhere
sample input worked as usual. I hope this isn’t another “Find the math trick” problem
@markw no trick, it’s a pure “understand the question” problem.
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.
https://github.com/Average-user/aoc2020/blob/main/src/day22.lisp CL again
Mine runs in 4sec. But probably changing list
s to double-queue
should improve that. I missed clojure's queues
@markw did you check the infinite loop test case?
Used queue for decks https://github.com/zelark/AoC-2020/blob/master/src/zelark/aoc_2020/day_22.clj
I see some queue
s there, nice
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.
What made you change your mind? Worry of performances regarding recursion?
Lots of subvecs, with pop it looks a bit nicer and simpler.
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.
@peterc 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
I would love to join the conversation, but I don’t know CL - sorry.
Today was even fun, I was afraid of complex combinatorics part 2 https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day22.clj
The funniest part of today’s puzzle is that the crab won the card game. Twice.
... based on the sample data.
Yeah, you know what? We should celebrate on the last day of the AoC. How about a Post-AoC online meetup party?
That’s a good idea. I also thought about something like that.
I am not big fan of parties but it would be nice to see everybody and say hi
We could make a watch party of r/adventofcode visualisations and jokes
Well after running all night my program did the honorable thing and committed seppuku
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
https://gist.github.com/Solaxun/92d3c438d290bc2a743f5d41d7bc4077
my input is hard coded up top
@markw ran my solution with your input, got 36463 with a strict condition
ok yeah i figured it was a bug in my solution
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.
the test input doesn’t trigger that condition, that’s why it works.
Ugh… well that was dumb. Wins the game not the round… oops.
I was thrown by (what seemed to me) as inconsistent use of “game” and “sub-game”