day06
This commit is contained in:
parent
592efaf1af
commit
fdcd179eb0
20
06/1.pl
Normal file
20
06/1.pl
Normal 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
29
06/2.pl
Normal 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
1
06/example
Normal file
@ -0,0 +1 @@
|
||||
0 2 7 0
|
1
06/input.txt
Normal file
1
06/input.txt
Normal file
@ -0,0 +1 @@
|
||||
5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6
|
Loading…
Reference in New Issue
Block a user