tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,13 @@
sub pascal
# Prints out $n rows of Pascal's triangle. It returns undef for
# failure and 1 for success.
{my $n = shift;
$n < 1 and return undef;
print "1\n";
$n == 1 and return 1;
my @last = (1);
foreach my $row (1 .. $n - 1)
{my @this = map {$last[$_] + $last[$_ + 1]} 0 .. $row - 2;
@last = (1, @this, 1);
print join(' ', @last), "\n";}
return 1;}

View file

@ -0,0 +1,3 @@
use bignum;
sub pascal { $_[0] ? unpack "A(A6)*", 1000001**$_[0] : 1 }
print "@{[map -+-$_, pascal $_]}\n" for 0..22;