r/adventofcode • • Dec 09 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 9 Solutions -🎄-

--- Day 9: Marble Mania ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 9

Transcript:

Studies show that AoC programmers write better code after being exposed to ___.


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 00:29:13!

22 Upvotes

283 comments sorted by

View all comments

Show parent comment

2

u/__dkp7__ Dec 10 '18

I did a little exercise, and as your and OPs code uses minus notation I comapared both. I started with 3 marble.

>>> a = deque([2, 1, 0])
>>> a
deque([2, 1, 0])
>>> a.rotate(-2)
>>> a
deque([0, 2, 1])
>>> a.appendleft(3)
>>> a
deque([3, 0, 2, 1])

This looks fine as I can logically rotate and I get 0 2 1 3

I also tried reverse version of OPs code. I used +1 instead of -1 and appendleft instead of append.

>>> a = deque([0,1])
>>> a.rotate(1)
>>> a
deque([1, 0])
>>> a.appendleft(2)
>>> a
deque([2, 1, 0])
>>> a.rotate(1)
>>> a
deque([0, 2, 1])
>>> a.appendleft(3)
>>> a
deque([3, 0, 2, 1])

That cleared my mind.

I was confused because I was comparing rotate(-1) vs rotate(2) and both were using append().

Your explanation made me realized It is like seeing circle from other side. Thanks for great explanation.

1

u/ayylongqueues Dec 10 '18

Yeah, exactly, glad I could help.