This commit is contained in:
Yanick Champoux 2017-12-06 11:50:31 -05:00
parent 592efaf1af
commit fdcd179eb0
4 changed files with 51 additions and 0 deletions

20
06/1.pl Normal file
View File

@ -0,0 +1,20 @@
use 5.20.0;
use experimental 'postderef';
#use List::SomeUtils qw/ min_by /;
use List::UtilsBy qw/ max_by/;
my @stacks = split ' ', <>;
my %seen;
until( $seen{ join ':', @stacks }++ ) {
warn "@stacks\n";
my $col = max_by { $stacks[$_] } 0..$#stacks;
my $v = $stacks[$col];
$stacks[$col] = 0;
$stacks[ ++$col % @stacks ]++ while $v--;
}
say scalar keys %seen;

29
06/2.pl Normal file
View File

@ -0,0 +1,29 @@
use 5.20.0;
use experimental 'postderef';
use List::UtilsBy qw/ max_by/;
my @stacks = split ' ', <>;
my %seen;
until( $seen{ join ':', @stacks }++ ) {
redistribute();
}
my $target = join ":", @stacks;
my $i = 0;
redistribute($i++) until $i and $target eq join ':', @stacks;
say $i;
sub redistribute {
warn "@stacks\n";
my $col = max_by { $stacks[$_] } 0..$#stacks;
my $v = $stacks[$col];
$stacks[$col] = 0;
$stacks[ ++$col % @stacks ]++ while $v--;
}

1
06/example Normal file
View File

@ -0,0 +1 @@
0 2 7 0

1
06/input.txt Normal file
View File

@ -0,0 +1 @@
5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6