main
Yanick Champoux 2017-12-28 12:12:10 -05:00
parent 4df9256d63
commit 1cf528262b
2 changed files with 93 additions and 0 deletions

34
25/1.pl Normal file
View File

@ -0,0 +1,34 @@
use 5.20.0;
my $state = 'A';
use experimental qw/ smartmatch /;
use List::AllUtils qw/ sum /;
my $iteration;
my @ribbon;
my $ri = 0;
my %chain = (
A => [ [ 1, 1, 'B' ], [ 0, -1, 'C' ] ],
B => [ [ 1, -1, 'A' ], [ 1, 1, 'D' ] ],
C => [ [ 0, -1, 'B' ], [ 0, -1, 'E' ] ],
D => [ [ 1, 1, 'A' ], [ 0, 1, 'B' ] ],
E => [ [ 1, -1, 'F' ], [ 1, -1, 'C' ] ],
F => [ [ 1, 1, 'D' ], [ 1, 1, 'A' ] ],
);
while( $iteration++ <= 1_2481_997 ) {
say $iteration unless $iteration % 100_000;
my $change = $chain{$state}[ $ribbon[$ri] ];
$ribbon[$ri] = $change->[0];
$ri += $change->[1];
if( $ri == -1 ) {
unshift @ribbon, 0;
$ri = 0;
}
$state = $change->[2];
}
say sum @ribbon;

59
25/input.yaml Normal file
View File

@ -0,0 +1,59 @@
In state A:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state B.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state C.
In state B:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state A.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state D.
In state C:
If the current value is 0:
- Write the value 0.
- Move one slot to the left.
- Continue with state B.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state E.
In state D:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.
If the current value is 1:
- Write the value 0.
- Move one slot to the right.
- Continue with state B.
In state E:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state F.
If the current value is 1:
- Write the value 1.
- Move one slot to the left.
- Continue with state C.
In state F:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state D.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.