diff --git a/06/1.pl b/06/1.pl new file mode 100644 index 0000000..dac01f0 --- /dev/null +++ b/06/1.pl @@ -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; + diff --git a/06/2.pl b/06/2.pl new file mode 100644 index 0000000..866a37b --- /dev/null +++ b/06/2.pl @@ -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--; +} + diff --git a/06/example b/06/example new file mode 100644 index 0000000..fd81a1c --- /dev/null +++ b/06/example @@ -0,0 +1 @@ +0 2 7 0 diff --git a/06/input.txt b/06/input.txt new file mode 100644 index 0000000..177ae3d --- /dev/null +++ b/06/input.txt @@ -0,0 +1 @@ +5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6