User:Ilmari Karonen/ahnentafel.pl

This is the perl script I used to make the unoptimized version of the Ahnentafel templates. See User:Ilmari Karonen/ahnentafel2.pl for a version that produces much more efficient (but much less readable) output.

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

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

print "\n";

for my $row ( 1 .. (1<<$depth)-1 ) { my $level = $depth; my $n = $row + (1<<$depth); $n >>= 1, $level-- until $n & 1; $n >>= 1;

my $gray1 = ($row ^ ($row<<1)); my $gray2 = ($row-1) ^ (($row-1)<<1) ^ 1;

my @line; my $boxn = sprintf "BX%03d", $n; my $seen = 0; for my $i ( 0 .. $depth-1 ) { my $quad = (($gray1>>$i)&1) + ((($gray2>>$i)&1)<<1); push @line, (["| | | | ", "| | | |,", "| | | |`"]->[$quad] ||                    ($seen++   ? "| | | |!": "|$boxn|("));   }    chop $line[0];    print "\n"; }

print "\n";

__END__