210 lines
21 KiB
Perl
Executable File
210 lines
21 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
use strict;
|
|
use Config;
|
|
$Config{useithreads} or
|
|
die('Recompile Perl with threads to run this program.');
|
|
use threads;
|
|
use Thread::Queue;
|
|
|
|
|
|
my @lines;
|
|
my $startx;
|
|
{
|
|
my $splits=0;
|
|
my %positions;
|
|
my %nextpositions;
|
|
while(my $line=<DATA>) {
|
|
chomp($line);
|
|
push @lines, $line;
|
|
for(my $i=0; $i<length $line; $i++) {
|
|
my $c = substr($line, $i, 1);
|
|
|
|
if($c eq 'S') {
|
|
$nextpositions{$i}=1;
|
|
$startx = $i;
|
|
} elsif($c eq '.' && $positions{$i}) {
|
|
$nextpositions{$i}=$positions{$i};
|
|
} elsif($c eq '^' && $positions{$i}) {
|
|
$splits++;
|
|
$nextpositions{$i-1} += $positions{$i};
|
|
$nextpositions{$i+1} += $positions{$i};
|
|
}
|
|
}
|
|
|
|
%positions=%nextpositions;
|
|
%nextpositions=();
|
|
}
|
|
|
|
print "Saw $splits splits\n";
|
|
}
|
|
|
|
my $times = calcpos_r($startx, 0);
|
|
print "$times timelines\n";
|
|
|
|
sub calcpos_r {
|
|
my($pos, $row)=@_;
|
|
|
|
|
|
for(;;) {
|
|
if($row >= @lines) {
|
|
return 1;
|
|
}
|
|
|
|
my $char = substr($lines[$row], $pos, 1);
|
|
if($char eq '.' || $char eq 'S') {
|
|
$row++;
|
|
next;
|
|
}
|
|
|
|
if($char eq '^') {
|
|
return calcpos_r($pos-1, $row+1) + calcpos_r($pos+1, $row+1);
|
|
}
|
|
|
|
die "Unknown character '$char' at $row : $pos\n";
|
|
}
|
|
}
|
|
|
|
|
|
__DATA__
|
|
......................................................................S......................................................................
|
|
.............................................................................................................................................
|
|
......................................................................^......................................................................
|
|
.............................................................................................................................................
|
|
.....................................................................^.^.....................................................................
|
|
.............................................................................................................................................
|
|
....................................................................^.^.^....................................................................
|
|
.............................................................................................................................................
|
|
...................................................................^...^.^...................................................................
|
|
.............................................................................................................................................
|
|
..................................................................^.^...^.^..................................................................
|
|
.............................................................................................................................................
|
|
.................................................................^...^.^.^.^.................................................................
|
|
.............................................................................................................................................
|
|
................................................................^.^.........^................................................................
|
|
.............................................................................................................................................
|
|
...............................................................^.^...^.^.^.^.^...............................................................
|
|
.............................................................................................................................................
|
|
..............................................................^.^.^.^.^.^.....^..............................................................
|
|
.............................................................................................................................................
|
|
.............................................................^.^.....^...^.^.^.^.............................................................
|
|
.............................................................................................................................................
|
|
............................................................^...^.....^.^...^.^.^............................................................
|
|
.............................................................................................................................................
|
|
...........................................................^.....^.^.^.^.^.^.^.^.^...........................................................
|
|
.............................................................................................................................................
|
|
..........................................................^...^...^.....^.^...^.^.^..........................................................
|
|
.............................................................................................................................................
|
|
.........................................................^.^.....^.^.....^.^.^.^.^.^.........................................................
|
|
.............................................................................................................................................
|
|
........................................................^...^.^.^.^...^.^.....^.....^........................................................
|
|
.............................................................................................................................................
|
|
.......................................................^.^.^.^.^.^.....^.....^.^.^.^.^.......................................................
|
|
.............................................................................................................................................
|
|
......................................................^.^.....^.^.^.....^.^...^...^.^.^......................................................
|
|
.............................................................................................................................................
|
|
.....................................................^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....................................................
|
|
.............................................................................................................................................
|
|
....................................................^.^.^...^.^.^.^.^.^.^.^...^...^.^.^.^....................................................
|
|
.............................................................................................................................................
|
|
...................................................^.^...^.^.^.^.^.^...^.^.^.^.^...^...^.^...................................................
|
|
.............................................................................................................................................
|
|
..................................................^.^.^.^...^.^.^.^.^.^.^...^.^...^.^...^.^..................................................
|
|
.............................................................................................................................................
|
|
.................................................^.^.^.^...^.^.......^.^.^.^.....^.^.^.^.^.^.................................................
|
|
.............................................................................................................................................
|
|
................................................^...^.^.^.^.^.^.^.^.^.^.....^.^.^...^.^.^...^................................................
|
|
.............................................................................................................................................
|
|
...............................................^.....^...^.^.^.^.^...^...^.^.^.^.^.^.^.^...^.^...............................................
|
|
.............................................................................................................................................
|
|
..............................................^...^.^...^.^...^.....^.^.^.^.^.^...^.^.^.......^..............................................
|
|
.............................................................................................................................................
|
|
.............................................^.^.^.^.^...^.^.^.^.^.^...^.....^.^.....^.^.^...^.^.............................................
|
|
.............................................................................................................................................
|
|
............................................^.^.^.^.^.^.^.^.^.^.^...^.^.....^...^.^...^.^.^.^...^............................................
|
|
.............................................................................................................................................
|
|
...........................................^.^.....^.^.....^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.....^...........................................
|
|
.............................................................................................................................................
|
|
..........................................^.^.^...^.....^.^.^.^.^...^.^.....^.^.^.^...^...^.^...^.^..........................................
|
|
.............................................................................................................................................
|
|
.........................................^.^...^.^.^.^.^.^.^.^.^.^.^.....^.....^.^.^.^.^.^.^.^.^.^.^.........................................
|
|
.............................................................................................................................................
|
|
........................................^.....^.^...^.^.^.^.....^.^.^.^...^...^.^.^.^.^...^.^...^.^.^........................................
|
|
.............................................................................................................................................
|
|
.......................................^.^.^.^.....^.^.^.......^.^.........^...^.^.^.^.....^.^.....^.^.......................................
|
|
.............................................................................................................................................
|
|
......................................^.^.....^.^.^...^.^...^.^.......^.^...^.^.^.^.^.^...^.....^.^...^......................................
|
|
.............................................................................................................................................
|
|
.....................................^.^.^...^.^.^.^.^.....^.^...^.....^.....^...^.^...^.......^.^.^.^.^.....................................
|
|
.............................................................................................................................................
|
|
....................................^.^.^...^...^.^.^...^.^...^.^.^.^.......^.....^.....^.^.......^.^.^.^....................................
|
|
.............................................................................................................................................
|
|
...................................^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.......^.^...^.^...^.^.^.^.^...^.^.^...................................
|
|
.............................................................................................................................................
|
|
..................................^...^.^.^.^...^.......^.^.^...^.^.......^.^.^.....^...^...^.^.^...^.^...^..................................
|
|
.............................................................................................................................................
|
|
.................................^...^.......^.^.^.....^.^...^.^...^.^.^.^.^.^.....^.^...^...^.^.^...^...^.^.................................
|
|
.............................................................................................................................................
|
|
................................^.^.^...^.^.^.^.^.^.^...^...^.^.......^.^...^.^.^...^.^...^.^.^.^.^...^...^.^................................
|
|
.............................................................................................................................................
|
|
...............................^.^.....^.^.^...^.^.^.^...^.........^.^.^.^.........^.^.^...........^.^.^.^...^...............................
|
|
.............................................................................................................................................
|
|
..............................^.^...^.^...^...^...^...^.^.^.^.^.^...^.^.^...^.^.^...^.....^.^.^...^...^.^.^...^..............................
|
|
.............................................................................................................................................
|
|
.............................^.^.^.^.^.^.^.....^.^.^.^.^.^.....^...^.^.^.......^.^.^.^.....^.........^.^.^.....^.............................
|
|
.............................................................................................................................................
|
|
............................^...^...^.^.^...^...^.^.^.^.^.^.^.^.^.^.......^.^.......^.^.....^.^.^.^...^.^...^...^............................
|
|
.............................................................................................................................................
|
|
...........................^.^.^...^.^.^.....^.....^.^.......^.^.^.....^.^.^...^.....^...^.^.^.^.....^.^.^.^.^.^.^...........................
|
|
.............................................................................................................................................
|
|
..........................^.....^.....^.^...^.^.^.^.^.^...^.^.^.^.^.^...^.^...^.^.^...^.^.^.....^.^.^...^.^...^...^..........................
|
|
.............................................................................................................................................
|
|
.........................^.^...^.^.^.^...^.^...^.^.........^.......^.^.^.^.^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^...^.........................
|
|
.............................................................................................................................................
|
|
........................^...^.^.^.^...^.^...^...^.^...^.^.^...^.^.^.^.^.^...^.^.^...^.......^.^.^.^.^...^.....^...^.^........................
|
|
.............................................................................................................................................
|
|
.......................^.^.^...^.^.^.....^.^...^.^.^...^...^.^.^...^.^.^...^.^.....^.^.^.^.^...^.^.........^.^.^.^.^.^.......................
|
|
.............................................................................................................................................
|
|
......................^.^.^.^...^.^.^.^.^.....^.^.^.....^.^.^.^.^...^.^.^.....^.^.....^...^.^.^.^.....^...........^.^.^......................
|
|
.............................................................................................................................................
|
|
.....................^.^.^.^.^.^...^.^.^.^.^.....^.^...^...^...^.^.^.^.^.....^.^.^.....^.^...^.......^.^.^.....^.^.^.^.^.....................
|
|
.............................................................................................................................................
|
|
....................^...^.^.......^.^.^.^.^.^.........^.^.^.^.......^.^...^.^.^.^.^.^.^.^.^...^.^.^.....^.^.^.^.^.^.^.^.^....................
|
|
.............................................................................................................................................
|
|
...................^.^.......^.^...^.^.^.^.^.^...^.^...^.^...^.....^.^.^...^.^...^.^.^.^.^...^...^.^.....^.^...^.^.^.^.^.^...................
|
|
.............................................................................................................................................
|
|
..................^.^.........^.^.^...^.^...^...^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^...^.....^...^.^..................
|
|
.............................................................................................................................................
|
|
.................^.^.^...^.^.^.^.^.......^.^.....^.^...^.^.^...^.^.^...^.^.^.^.^...^.......^.^...^.^.^.........^.^...^.^.^.^.................
|
|
.............................................................................................................................................
|
|
................^.....^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^...^...^.^...^.^.^.^...^.^.^.^.^.^.....^...^.....^.^................
|
|
.............................................................................................................................................
|
|
...............^.....^.^.^.^.^.^.^.^.^.^...^.^...^...^...^...^...^.^.^.^.........^.^.^.^.^...^.....^.^.......^...^...^.^.^.^.^...............
|
|
.............................................................................................................................................
|
|
..............^.^.^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^...^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.....^.^...^.^.^.^.^...^.....^.....^..............
|
|
.............................................................................................................................................
|
|
.............^.^...^.^.....^.......^.....^.....^.^...^.^.^.^.....^.^.....^.....^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.............
|
|
.............................................................................................................................................
|
|
............^.^...^.^.....^.^.^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^.^.^...^.....^.^...^...^.........^.^...^.^...^.^.^.^.^.^.^.^...^............
|
|
.............................................................................................................................................
|
|
...........^...^.^.^...^.^...^...^.^...^...^.^.^.^...^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^...^.^.^.....^.^.^.^...........
|
|
.............................................................................................................................................
|
|
..........^.^.........^.^...^.....^.^.^.^.^.^.^.^...^...^...^.^.^.^.^...^.^.^...^...^...^.^.^...^.^.^.^...^.^.^.^...^.....^...^...^..........
|
|
.............................................................................................................................................
|
|
.........^.^.^.^...^...^.^.^.^...^.^.^.^.^.^.....^...^.^.....^.^...^...^.^...^.^.^.^...^.^...^...^.^.^.^...^...^.....^.^.^...^...^.^.........
|
|
.............................................................................................................................................
|
|
........^...^.^.^.^...^.^.^.^.^.^.^...^.^.^.........^...^.^.^.^.....^.^...^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^...^.^.^.....^.^.....^.^.^........
|
|
.............................................................................................................................................
|
|
.......^.......^.^.^.^...^.^...^.^...^.^.^.^.^.^.^.^.^...^.^.^...^...^...^.^.^...^.^.^...^.^.^.^.^.^.^...^.^.....^.^.^...^.^.^...^.^.^.......
|
|
.............................................................................................................................................
|
|
......^...^...^.^.....^.^.^.^.^.^.^...^.^.^.^...^.^.^...^.^.^.....^.^.^.....^.^.^.^.^...^.^.^.^.....^.^.^...^.^.^.....^.^.^.^.^.^...^.^......
|
|
.............................................................................................................................................
|
|
.....^.....^.^.^.^.^...^.........^.....^.......^.^.^...^.^.......^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^...^...^.^.^...^...^.^...^.^.....^.^.....
|
|
.............................................................................................................................................
|
|
....^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.....^.^.^.....^.^.^.^...^.....^.^.....^...^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^...^.^.^...^.^.^...^...^....
|
|
.............................................................................................................................................
|
|
...^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.....^...^.^.^.^.^.^.....^.^.^.^.^.^...^.......^.^...^...^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^.^...^...
|
|
.............................................................................................................................................
|
|
..^.^.^.^...^.^.^.^.^...^.....^...^.^.^...^...^.^.^.^...^...^.^.^...^...........^.^.^.^.......^...^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^..
|
|
.............................................................................................................................................
|
|
.^.^.^.^.^.^.^.^.^.^.^.......^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^.^.......^.^.^.^.^...^...^.^.^.^.......^.....^.
|
|
............................................................................................................................................. |