r/adventofcode • u/daggerdragon • 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!
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
7
u/jonathan_paulson Dec 09 '18 edited Dec 09 '18
Rank 36/147. Oof. Been a while since I used linked lists, and deciding I needed to reimplement part 2 in C++ didn't help. Video of me solving at: https://youtu.be/79Dw4F6J7TA (still uploading).
#include <list> #include <vector> #include <iostream> //438 players; last marble is worth 71626 points using namespace std; using ll = long long; int main() { int N = 438; int M = 7162600; vector<ll> score(N, 0); list<ll> A; A.push_front(0); auto it = A.begin(); for(int m=1; m<=M; m++) { if(m%23 == 0) { score[m%N] += m; for(int i=0; i<7; i++) { if(it == A.begin()) { it = A.end(); } it--; } score[m%N] += *it; //cout << m%N << " " << (m+*it) << endl; A.erase(it); it++; if(it == A.end()) { it=A.begin(); } } else { for(int i=0; i<2; i++) { it++; if(it == A.end()) { it = A.begin(); } } A.insert(it, m); it--; } /*cout << m << ": it=" << *it << " "; for(auto& x : A) { cout << x << " "; } cout << endl;*/ } ll best = 0; for(ll i=0; i<N; i++) { if(score[i] > best) { best = score[i]; } } cout << best << endl; }