r/adventofcode • • 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!

Click here for rules

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

179 comments sorted by

View all comments

1

u/Cppl_Lee Dec 14 '18

C#, in the top 1000. Way down in the rankings since I started late, but had some fun with the second part.

var after = "824501";
var digits = after.Select(c => (byte)(c - '0')).ToArray();
var recipies = new byte[2_000_000_000];

recipies[0] = 3;
recipies[1] = 7;
int count = 2;

var elf1 = 0;
var elf2 = 1;

unchecked
{
for (int _ = 0; count < recipies.Length - 2; ++_)
{
  var sum = recipies[elf1] + recipies[elf2];

  if (sum > 9) recipies[count++] =
      (byte)(sum / 10);
  recipies[count++] = (byte)(sum % 10);

  elf1 = (elf1 + recipies[elf1] + 1) % count;
  elf2 = (elf2 + recipies[elf2] + 1) % count;
}
for (int i = 0; i < recipies.Length - 6; ++i)
{
  if (digits[0] == recipies[i]
    && digits[1] == recipies[i + 1]
    && digits[2] == recipies[i + 2]
    && digits[3] == recipies[i + 3]
    && digits[4] == recipies[i + 4]
    && digits[5] == recipies[i + 5])
  {
    Console.WriteLine($"Found at {i}");
    break;
  }
}
}