diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-04-10 10:44:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-10 10:44:14 +0100 |
| commit | e57020f83c26d151fc8c2d8d8475d15138cde60a (patch) | |
| tree | aeef181c1147b83a9d12a09d28d39ffa917b8961 /challenge-003 | |
| parent | e18516103328caf1bd59d53c19996b3de3b8609d (diff) | |
| parent | 75100ccacdb6b065a46a3bd6ac9015f59d2b9ead (diff) | |
| download | perlweeklychallenge-club-e57020f83c26d151fc8c2d8d8475d15138cde60a.tar.gz perlweeklychallenge-club-e57020f83c26d151fc8c2d8d8475d15138cde60a.tar.bz2 perlweeklychallenge-club-e57020f83c26d151fc8c2d8d8475d15138cde60a.zip | |
Merge pull request #39 from cliveholloway/cliveholloway-challenge002
solution for Challenge 2, week 3
Diffstat (limited to 'challenge-003')
| -rw-r--r-- | challenge-003/cliveholloway/README | 1 | ||||
| -rwxr-xr-x | challenge-003/cliveholloway/perl5/ch-2.pl | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/challenge-003/cliveholloway/README b/challenge-003/cliveholloway/README new file mode 100644 index 0000000000..b69201296e --- /dev/null +++ b/challenge-003/cliveholloway/README @@ -0,0 +1 @@ +Solution by Clive Holloway diff --git a/challenge-003/cliveholloway/perl5/ch-2.pl b/challenge-003/cliveholloway/perl5/ch-2.pl new file mode 100755 index 0000000000..be67bd4673 --- /dev/null +++ b/challenge-003/cliveholloway/perl5/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use v5.012; + +my @out=([1],[1,1]); + +for (3..$ARGV[0]) { + my @new_row=(1,@{$out[-1]}); + for (1..$#{$out[-1]}) { + $new_row[$_] = $out[-1][$_-1] + $out[-1][$_]; + } + push @out, \@new_row; +} + +# format data for output - obviously you'll run out of terminal at some point, +# so, this is just a pretty demo output +my $longest_length = length("@{$out[-1]}"); +for (0..$#out) { + $out[$_] = "@{$out[$_]}"; + my $this_length = length($out[$_]); + say ' 'x(($longest_length-$this_length)/2).$out[$_]; +} |
