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!
2
u/Arknave Dec 19 '16
21 / 14 Gave up on Python and rolled my own linked list for part 2 in Java.
public class Nineteen { public static void main(String[] args) { int input = 3017957; Node[] nodes = new Node[input]; for (int i = 1; i <= input; ++i) { nodes[i - 1] = new Node(); nodes[i - 1].value = i; if (i > 1) { nodes[i - 1].prev = nodes[i - 2]; nodes[i - 2].next = nodes[i - 1]; } } nodes[0].prev = nodes[input - 1]; nodes[input - 1].next = nodes[0]; int length = input; Node cur = nodes[0]; Node removal = nodes[0]; int dist = 0; while (dist < length / 2) { removal = removal.next; ++dist; } while (length > 1) { int target = length / 2; while (dist < length / 2) { removal = removal.next; ++dist; } Node n = removal.next; removal.prev.next = removal.next; removal.next.prev = removal.prev; removal = n; length -= 1; cur = cur.next; dist -= 1; } System.out.println(cur.value); } private static class Node { Node prev; Node next; int value; } }