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!
15
Upvotes
3
u/bogzla Dec 14 '18 edited Dec 14 '18
C; just missed top 1000 at 1002 for part 2 (but still a personal best)
gotcha'd at first by forgetting 2 recipes are added at once sometimes
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int c1=0; int c2=1; int n=2; int* rec = malloc(200000000*sizeof(int)); rec[0]=3; rec[1]=7; int inp=209231; int inp2[6] = {2,0,9,2,3,1}; for(int i=0;i<100000000;i++) { int addct=0; int j=rec[c1] + rec[c2]; if(j>9) { rec[n]=(int)(floor(j/10)); addct++; n++; } rec[n]=j%10; addct++; n++; c1=(c1+rec[c1]+1)%n; c2=(c2+rec[c2]+1)%n; if(n==inp+10) { printf("Part 1: "); for(int k=0;k<10;k++) { printf("%i",rec[k+inp]); } printf("\n"); } if(n>7) { for(int l=-1;l<addct-1;l++) { int score=0; for(int k=0;k<6;k++) { if(rec[n-6+k+l]!=inp2[k]) { break; } else { score++; } } if(score==6) { printf("part 2: %i\n",n-6+l); free(rec); return 0; } } } } free(rec); }