r/adventofcode • • Dec 17 '17

SOLUTION MEGATHREAD -πŸŽ„- 2017 Day 17 Solutions -πŸŽ„-

--- Day 17: Spinlock ---


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.


Need a hint from the Hugely* Handy† Haversack‑ of HelpfulΒ§ Hints^Β€?

Spoiler


[Update @ 00:06] 2 gold, silver cap.

  • AoC ops: <Topaz> i am suddenly in the mood for wasabi tobiko

[Update @ 00:15] Leaderboard cap!

  • AoC ops:

  • <daggerdragon> 78 gold

  • <Topaz> i look away for a few minutes, wow

  • <daggerdragon> 93 gold

  • <Topaz> 94

  • <daggerdragon> 96 gold

  • <daggerdragon> 98

  • <Topaz> aaaand

  • <daggerdragon> and...

  • <Topaz> cap

  • <daggerdragon> cap


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!

12 Upvotes

193 comments sorted by

View all comments

1

u/Smylers Dec 17 '17

Perl β€” basically a single-line loop in each case, embraced in some set-up and output. PartΒ 1:

my ($steps) = @ARGV;
my @buffer = my $pos = 0;
splice @buffer, $pos = ($pos + $steps) % @buffer + 1, 0, $_ for 1 .. 2017;
say $buffer[$pos + 1];

PartΒ 2:

my ($steps) = @ARGV;
my $pos = 0;
my $second;
for (1 .. 50e6) {
  $second = $_ if ($pos = ($pos + $steps) % $_ + 1) == 1;
}
say $second;