]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/38.pl
The rest of Year 2016
[aoc.git] / 2016 / 38.pl
diff --git a/2016/38.pl b/2016/38.pl
new file mode 100755 (executable)
index 0000000..046adb6
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+# my $in = 3004953;
+my $in = shift;
+
+my @elves = (1 .. $in);
+my $now = 0;
+while (@elves > 1) {
+       my $steal = $now + int(@elves/2);
+       $steal -= @elves if $steal > $#elves;
+       say "now $now, steal $steal, total ", scalar @elves, ": ", join(' ', @elves);
+       splice(@elves, $steal, 1);
+       $now++ if $steal > $now;
+       $now = 0 if $now > $#elves;
+}
+say $elves[0];