#!/usr/bin/perl use strict; my $n = 10; for my $i (0 .. $n) { for my $j (0 .. $i) { my $coefficient = nCr($i, $j); if ($coefficient % 2) { print '#'; } else { print ' '; } } print "\n"; } # returns n!/r!(n-r)! sub nCr { my $n=shift; my $r=shift; return int nFactorial($n) / int nFactorial($r) * int nFactorial($n-$r); } # like the name says, n! sub nFactorial { my $n=shift; my $product = 1; while($n>0) { $product *= $n--; } return $product; }