User:Ilmari Karonen/ahnentafel2.pl

This is the perl script I used to make the optimized versions Ahnentafel templates. You can use it to make more if you want.

See User:Ilmari Karonen/ahnentafel.pl for a version that produces more readable but much less efficient output.

use strict;
 * 1) !/usr/bin/perl -w

my $depth = shift or die "Usage: $0 \n";

my $nbsp = qq(  );

sub box { my ($n, $col) = @_; print STDERR "*"; my (@row1, @row2); push @row1, ($n & 1 ? qq() : qq). qq($nbsp ) if $col > 1; push @row2, (!($n & 1) ? qq() : qq). qq($nbsp ) if $col > 1;

push @row1, qq( );

push @row1, qq($nbsp ) if $col < $depth; push @row2, qq( $nbsp ) if $col < $depth;

return (join("\n", @row1, ""), join("\n", @row2, "")); }

sub gap { my ($rows, $odd, $col) = @_; my $char = ($odd ? " " : "-"); print STDERR $char x $rows; return unless $rows; $rows *= 2; my $cols = ($col == 1 || $col == $depth ? 2 : 3); my $style = (!$odd ? ' style="border-left: 1px solid black;"' : ''); return (qq($nbsp \n), ("") x ($rows-1)); }

my @table; for my $col (1 .. $depth) { my @col; my $step = 1 << ($depth - $col);

push @col, gap($step-1, 1, $col);

for my $n ( 1<<($col-1) .. (1<<$col)-2 ) { push @col, box($n, $col), gap(2*$step-1, $n & 1, $col); }

push @col, box((1<<$col)-1, $col), gap($step-1, 1, $col);

print STDERR "\n"; push @table, \@col; }

print ' \n";

__END__