]> www.fi.muni.cz Git - aoc.git/blob - 2016/38.pl
Day 25: examining the input
[aoc.git] / 2016 / 38.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use v5.30;
5
6 # my $in = 3004953;
7 my $in = shift;
8
9 my @elves = (1 .. $in);
10 my $now = 0;
11 while (@elves > 1) {
12         my $steal = $now + int(@elves/2);
13         $steal -= @elves if $steal > $#elves;
14         say "now $now, steal $steal, total ", scalar @elves, ": ", join(' ', @elves);
15         splice(@elves, $steal, 1);
16         $now++ if $steal > $now;
17         $now = 0 if $now > $#elves;
18 }
19 say $elves[0];