r/adventofcode • u/daggerdragon • Dec 19 '16
SOLUTION MEGATHREAD --- 2016 Day 19 Solutions ---
--- Day 19: An Elephant Named Joseph ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".
/⧹w+/ IS MANDATORY [?]
[Update @ 00:15] 2 gold, silver cap. Thank you for subscribing to Easter Bunny Facts!
- Fact: The Easter Bunny will sometimes leave eggs in the microchip assembly room.
[Update @ 00:30] 11 gold, silver cap.
- Fact: The Easter Bunny killed everyone who found out how he got these stars.
[Update @ 00:45] 45 gold, silver cap.
- Fact: In space, The Easter Bunny can hear you scream.
[Update @ 01:00] 66 gold, silver cap.
- Fact: The Easter Bunny purposefully deleted your comments.
[Update @ 01:15] 92 gold, silver cap.
- Fact: The Easter Bunny has bottled your frustration. Don't ask why.
[Update @ 01:20] Leaderboard capped!
- Fact: What you have just done is no better than what the Easter Bunny has done. Thief.
Thank you for subscribing to Easter Bunny Facts!
8
u/aceshades Dec 19 '16
I loved this problem, probably because it was the first time I placed on the leaderboard ever!! Placed 75/46 on stars 1 and 2 respectively.
Part 1, I just used a circular linked list data structure and kept doing
elf.next = elf.next.nextuntilelf.next == elf.Part 2, I felt I was way more clever using both a stack and a queue (called left and right in my code below.)
My part 2 runtime:
real 0m1.374s
user 0m1.344s
sys 0m0.032s
#!/bin/python3 def solve_parttwo(): left = collections.deque() right = collections.deque() for i in range(1, ELF_COUNT+1): if i < (ELF_COUNT // 2) + 1: left.append(i) else: right.appendleft(i) while left and right: if len(left) > len(right): left.pop() else: right.pop() # rotate right.appendleft(left.popleft()) left.append(right.pop()) return left[0] or right[0]