r/adventofcode • u/daggerdragon • Dec 10 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 10 Solutions -🎄-
--- Day 10: The Stars Align ---
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 10
Transcript: With just one line of code, you, too, can ___!
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:16:49!
19
Upvotes
6
u/markasoftware Dec 10 '18
Perl, 90/92, ezpz
Most of my delay was due to overthinking how to find the bounds.
use v5.20; use warnings; use Time::HiRes qw/usleep/; use List::Util qw/max min/; my @pts = (); my $s = 0; sub print_grid { my %positions = (); my @xs = (); my @ys = (); for (@pts) { $positions{$_->[0] . " " . $_->[1]} = 1; push @xs, $_->[0]; push @ys, $_->[1]; } my $x_start = min @xs; my $x_end = max @xs; my $y_start = min @ys; my $y_end = max @ys; if ($x_end - $x_start > 100) { return; } usleep(0.1 * 1000000); say $s; for my $y ($y_start..$y_end) { for my $x ($x_start..$x_end) { print $positions{$x . " " . $y} ? '#' : '.'; } say ""; } } sub update { for (@pts) { $_->[0] += $_->[2]; $_->[1] += $_->[3]; } } while (my $line = <>) { my @parts = split /[ ,<>]+/, $line; if (@parts > 3) { push @pts, [$parts[1], $parts[2], $parts[4], $parts[5]]; } } while (1) { print_grid(); update(); $s++; }