adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
markw 2020-12-22T05:40:17.045200Z

tonight’s puzzle… reading comprehension

➕ 1
2020-12-22T10:49:17.060300Z

On this one, I miss a detail which costs me at least 20 minutes. 😄

2020-12-22T05:55:06.045400Z

Day 22 answers thread - Post your answers here

2020-12-22T10:47:45.060Z

I should definitely look to queues ! Better performance and neater syntax.

genmeblog 2020-12-22T13:48:31.060700Z

around 250ms for part2 https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2020/day22.clj

👍 3
nbardiuk 2020-12-22T14:14:19.061200Z

today problem is hard to compare, different inputs have very different number of steps. Using the same code on my machine my input runs 1s, @misha's750ms and @tsulej’s 150ms

👍 3
➕ 1
euccastro 2020-12-22T14:39:51.061700Z

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

👍 1
euccastro 2020-12-22T14:52:01.062500Z

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

euccastro 2020-12-22T14:56:07.062800Z

@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

euccastro 2020-12-22T14:56:46.063100Z

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?

genmeblog 2020-12-22T14:59:53.063500Z

> if there was a previous round in this game that had exactly the same cards in the same order in the same players' decks

genmeblog 2020-12-22T15:00:51.063700Z

if any of the player has been seen game stops

nbardiuk 2020-12-22T15:13:01.064100Z

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

euccastro 2020-12-22T15:14:28.064500Z

see where the apostrophe is placed. I think that basically means you bail if you see a previous game state again

euccastro 2020-12-22T15:15:29.064800Z

yes, but maybe player 2 would have won if the game hadn't been aborted?

euccastro 2020-12-22T15:15:59.065Z

(obvs. that isn't happening in your input, so who knows)

1
misha 2020-12-22T15:42:38.065900Z

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

misha 2020-12-22T15:44:17.066200Z

regardless, you might want to run or option (as it terminates faster), and see whether you'll get a star

benoit 2020-12-22T15:54:39.066500Z

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)

👍 4
👆 1
euccastro 2020-12-22T17:18:15.070900Z

yes, I've just checked that the or version works in my data, and runs in under 1/3 of the time

euccastro 2020-12-22T17:20:25.071100Z

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)

2020-12-22T17:27:24.072400Z

my interpretation is the same

peterc 2020-12-22T17:30:37.072600Z

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

peterc 2020-12-22T17:31:59.072900Z

I get the same result as well using the less restrictive case, and my time goes from ~8s to under 1s

2020-12-22T19:37:36.080800Z

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.

👍 1
rjray 2020-12-22T20:16:33.081200Z

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

peterc 2020-12-22T06:03:47.046100Z

Nice! What was the run time for part2 for you?

2020-12-22T06:04:16.046300Z

4.5 seconds on my computer, about half of anybody else’s computer. The code could me improved, I am sure.

rjray 2020-12-22T06:08:27.046900Z

Finally, a pair for which Clojure is wonderfully suited… https://github.com/rjray/advent-2020-clojure/blob/master/src/advent_of_code/day22.clj

👍 5
rjray 2020-12-22T06:08:44.047300Z

Pretty sure I can get that shorter. Tomorrow.

rjray 2020-12-22T06:09:13.047500Z

Also, the title of this thread is “Day 21 answers…” 🙂.

👌 1
😝 1
2020-12-22T06:18:01.048400Z

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.

peterc 2020-12-22T06:23:25.048600Z

ahh I didnt look at your code yet, my part-2 answer was chugging along, so its probably not correct

markw 2020-12-22T06:47:25.049Z

waiting for part 2 to finish.. must have bug somewhere

markw 2020-12-22T06:47:43.049200Z

sample input worked as usual. I hope this isn’t another “Find the math trick” problem

2020-12-22T06:50:26.049400Z

@markw no trick, it’s a pure “understand the question” problem.

Average-user 2020-12-22T06:53:46.049600Z

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.

2020-12-22T06:54:38.049800Z

This rules of avoiding repeating configuration is similar in the game of Go.

⚫ 4
⚪ 4
Average-user 2020-12-22T06:55:00.050Z

https://github.com/Average-user/aoc2020/blob/main/src/day22.lisp CL again

👍 2
🙈 2
🔞 1
😉 1
1
Average-user 2020-12-22T06:56:28.050400Z

Mine runs in 4sec. But probably changing lists to double-queueshould improve that. I missed clojure's queues

peterc 2020-12-22T06:57:10.050800Z

@markw did you check the infinite loop test case?

2020-12-22T06:58:34.051100Z

Used queue for decks https://github.com/zelark/AoC-2020/blob/master/src/zelark/aoc_2020/day_22.clj

🦜 1
🎉 4
Average-user 2020-12-22T06:59:45.052Z

I see some queues there, nice

2020-12-22T07:01:40.052400Z

I avoided using a queue when I realized that it would not display its values in my REPL, I chose a vector instead.

⏱️ 1
2020-12-22T07:04:25.052700Z

I firstly went with vectors, but after the part 1 had been solved I changed my mind.

2020-12-22T07:05:21.053Z

What made you change your mind? Worry of performances regarding recursion?

2020-12-22T07:08:27.053200Z

Lots of subvecs, with pop it looks a bit nicer and simpler.

2020-12-22T07:10:35.053700Z

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.

➕ 1
markw 2020-12-22T07:38:20.054300Z

@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

➕ 1
2020-12-22T07:44:43.054500Z

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

nbardiuk 2020-12-22T07:46:52.054700Z

Today was even fun, I was afraid of complex combinatorics part 2 https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day22.clj

👍 3
2020-12-22T07:56:59.056Z

The funniest part of today’s puzzle is that the crab won the card game. Twice.

🦀 4
2020-12-23T02:04:28.082400Z

... based on the sample data.

2020-12-22T08:10:17.057400Z

Yeah, you know what? We should celebrate on the last day of the AoC. How about a Post-AoC online meetup party?

👍 3
2020-12-22T08:13:34.057600Z

That’s a good idea. I also thought about something like that.

2
nbardiuk 2020-12-22T08:36:27.057900Z

I am not big fan of parties but it would be nice to see everybody and say hi

nbardiuk 2020-12-22T08:38:09.058100Z

We could make a watch party of r/adventofcode visualisations and jokes

markw 2020-12-22T16:55:57.068Z

Well after running all night my program did the honorable thing and committed seppuku

markw 2020-12-22T16:56:47.069Z

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

markw 2020-12-22T16:57:53.069700Z

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

euccastro 2020-12-22T17:11:38.070800Z

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

markw 2020-12-22T17:26:06.072300Z

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

markw 2020-12-22T17:41:40.074Z

my input is hard coded up top

2020-12-22T17:50:33.074500Z

@markw ran my solution with your input, got 36463 with a strict condition

markw 2020-12-22T17:51:05.074900Z

ok yeah i figured it was a bug in my solution

markw 2020-12-22T17:51:19.075300Z

probably something obvious that i’m just not getting, but it doesn’t help that the test input works perfectly, line-by line

2020-12-22T17:53:55.076700Z

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.

2020-12-22T17:56:13.077600Z

the test input doesn’t trigger that condition, that’s why it works.

markw 2020-12-22T18:06:08.078200Z

Ugh… well that was dumb. Wins the game not the round… oops.

2020-12-22T19:06:31.079100Z

https://twitter.com/luiyo/status/1341454365731774464

🦀 1
1
AC 2020-12-22T19:16:00.079800Z

I was thrown by (what seemed to me) as inconsistent use of “game” and “sub-game”

rjray 2020-12-22T20:18:21.081700Z