#! perl -slw use strict; $|++; our $DEPTH ||= 3; sub fract2D { use integer; my( $x, $y, $depth ) = @_; if( $x < 16 and $y < ) { ## A block on the major diagonal return $x == $y ? $depth : $depth -1; } elsif( $depth > 1 ) { return fract2D( $x % 4**$depth, $y % 4**$depth, $depth -1 ); } else { return fract2D( $x % 4**$depth, $y % 4**$depth, $depth ); } } for my $depth ( $DEPTH ) { for my $y ( 0 .. 4**$depth-1 ) { my $c = 0; for my $x ( 0 .. 4 ** $depth -1 ) { printf +( ( ++$c % 4 ) == 0 ? " %2d " : " %2d" ), fract2D( $x, $y, $depth ); } print +( $y % 4 ) == 3 ? "\n" : ''; } print ''; }