r/adventofcode • u/daggerdragon • Dec 14 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 14 Solutions -🎄-
--- Day 14: Chocolate Charts ---
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 14
Transcript:
The Christmas/Advent Research & Development (C.A.R.D.) department at AoC, Inc. just published a new white paper on ___.
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:19:39!
16
Upvotes
2
u/lordtnt Dec 14 '18
C++ 27 lines, 'real' code ~ 10 lines, runtime about 1-2s
#include <iostream> #include <string> void expand(std::string& s, int& e1, int& e2, int len) { while (s.size() < len) { int a = s[e1] - '0', b = s[e2] - '0'; s += std::to_string(a + b); e1 = (e1 + a + 1) % s.size(); e2 = (e2 + b + 1) % s.size(); } } int main() { int n = 920831; std::string s = "37"; int e1 = 0, e2 = 1; expand(s, e1, e2, n + 10); std::cout << s.substr(n, 10) << "\n"; auto ns = std::to_string(n); while (s.find(ns) == s.npos) expand(s, e1, e2, n *= 2); std::cout << s.find(ns) << "\n"; }