Twos in Pascals triangle by

$rows = 62;\x0d
\x0d
$pascal[0][0] = 1;\x0d
print " " x ($rows + 1), divBy2($pascal[0][0]), " " x ($rows + 1), "\n";\x0d
\x0d
foreach $i (0..$rows) {\x0d
   print " " x ($rows - $i);\x0d
   foreach $j (0..@pascal) {\x0d
      $pascal[$i + 1][$j] += $pascal[$i][$j - 1] if $j >= 1;\x0d
      $pascal[$i + 1][$j] += $pascal[$i][$j] if $j <= $i; \x0d
      print divBy2($pascal[$i + 1][$j]), " "; \x0d
   }\x0d
   print " " x ($rows - $i - 1), "\n";\x0d
}\x0d
\x0d
sub divBy2 {\x0d
   my $n = shift @_;\x0d
   my $div = 0;\x0d
   while ($n % 2 == 0 && $n > 0) {\x0d
      $n /= 2;\x0d
      $div++;\x0d
   }\x0d
   return $div if $div;\x0d
   return "."\x0d
}

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

To protect the system from spam, please input your favorite sport (hint: I believe its name must start with 'g', case insensitive)

download

return to the top page