6 chomp (my $state = <>);
14 my ($src, $dst) = split / => /;
23 if ($state !~ /^\.\.\.\./) {
24 $state = '....' . $state;
27 $state = $state . '....' if $state !~ /\.\.\.\.$/;
28 while ($state =~ /^\.\.\.\.\./) {
32 while ($state =~ /\.\.\.\.\.$/) {
39 for my $p (2 .. length($state)-3) {
40 my $src = substr($state, $p-2, 5);
41 # die "no rule for $src" if !exists $rules{$src};
42 substr($nstate, $p, 1) = $rules{$src} if defined $rules{$src};
45 last if ($seen{$state});
46 $seen{$state} = [ $gen, $off ];
50 say "state $gen off $off";
52 say "is equal to ", $seen{$state}[0], ' ', $seen{$state}[1];
54 $off += (50000000000 - $gen) * ($off - $seen{$state}[1]);
56 while ($state =~ /#/g) {
57 $sum += pos($state) + $off - 1;