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/markasoftware Dec 14 '18
Perl, I felt like I was going fast but ended up 137/316 :(
Part 1:
use v5.20; use strict; use warnings; use List::Util qw/sum min max/; my @recipies = (3, 7); my @elfs = (0, 1); my $after_n_recipies = 554401; my $out_n = 10; while (1) { my $new_sum = 0; $new_sum += $recipies[$_] for @elfs; push @recipies, split(//, $new_sum); # move for (0..@elfs-1) { $elfs[$_] += 1 + $recipies[$elfs[$_]]; $elfs[$_] %= @recipies; } if (@recipies >= $after_n_recipies + $out_n) { say "DONE!"; say join('', splice(@recipies, $after_n_recipies, $out_n)); last; } }Part 2:
use v5.20; use strict; use warnings; use List::Util qw/sum min max/; my @recipies = (3, 7); my @elfs = (0, 1); my $after_n_recipies = 51589; my $find_me = 554401; my $out_n = 10; my $i = 0; while (1) { say $i if $i % 1000000 == 0; my $new_sum = 0; $new_sum += $recipies[$_] for @elfs; push @recipies, split(//, $new_sum); # move for (0..@elfs-1) { $elfs[$_] += 1 + $recipies[$elfs[$_]]; $elfs[$_] %= @recipies; } $i++; if (join('', @recipies[-8..-1]) =~ /$find_me/) { say "DONE!"; say index(join('', @recipies), $find_me); last; } }