divide rectangles by BioFALSE(author)

sub rect {
\x09my ($n, $m) = @_;
\x09
\x09$g = '+' . '-' x $m . '+';
\x09my @a = ($g) x 2;
\x09$g = '|' . ' ' x $m . '|';
\x09@a = (@a, ($g) x $n)[1 .. $n+1, 0];
\x09return @a;
\x09
\x09}

sub divide {
\x09my ($n, $m, @a) = @_;
\x09my $le;
\x09$le = length for @a;
\x09my $w = ($le - 2) / $m;
\x09%h = ('-' => '+', ' ' => '|');
\x09s/([- ]{$w}) (?! [+|])/ $1 . join ' ', ( $h{ chop (my $i = $1) } ) x 2 /gxe for @a;
\x09my $jump = (@a - 2) / $n;

\x09my @c;
\x09(push @c, $_), !$_ || $_ % $jump or push @c, (0) x 2  for 0 .. @a-2;
\x09pop @c;

\x09return @a[@c]
\x09}
\x09
$, = $/;

@q = qw(
\x094 6 2 3
\x093 4 3 2
\x095 2 1 2
\x092 8 2 1
\x096 3 1 1
\x094 7 2 7
\x091 2 1 2
\x094 9 2 3
\x098 12 4 6
\x097 14 1 7
\x099 9 3 9
\x095 22 1 11
);

while(@q){
#\x09print 
\x09@_ = rect (shift @q, shift @q), '';
\x09
\x09my ($n, $m) = (shift @q, shift @q);
#\x09print $n . ' ' . $m . $/;
#\x09print
\x09divide ($n, $m, @_), '';

\x09}
\x09
my @a = ();
while(<>){
\x09chomp;
\x09
\x09!/\d/ ? (push @a, $_) :
\x09\x09do {
\x09\x09\x09my ($n, $m) = split;
\x09\x09\x09print
\x09\x09\x09divide ($n, $m, @a), '';
\x09\x09\x09@a = ();
\x09\x09\x09};
\x09
\x09}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page