aboutsummaryrefslogtreecommitdiff
path: root/challenge-003
diff options
context:
space:
mode:
authorFrancis Whittle <FJ.Whittle@gmail.com>2019-04-11 02:13:18 +1000
committerFrancis Whittle <FJ.Whittle@gmail.com>2019-04-11 02:13:18 +1000
commit621d4f7037e73f35025a119bd74ef90645f754bf (patch)
treeb58c116e4b4b5a78ee04e55fa923169a5acc26b7 /challenge-003
parent507cd92fef765186b1473f86e22efca98af068b2 (diff)
downloadperlweeklychallenge-club-621d4f7037e73f35025a119bd74ef90645f754bf.tar.gz
perlweeklychallenge-club-621d4f7037e73f35025a119bd74ef90645f754bf.tar.bz2
perlweeklychallenge-club-621d4f7037e73f35025a119bd74ef90645f754bf.zip
fjwhittle: week 3, part 2, perl 6
Diffstat (limited to 'challenge-003')
-rw-r--r--challenge-003/fjwhittle/perl6/ch-2.p624
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-003/fjwhittle/perl6/ch-2.p6 b/challenge-003/fjwhittle/perl6/ch-2.p6
new file mode 100644
index 0000000000..5149fb1447
--- /dev/null
+++ b/challenge-003/fjwhittle/perl6/ch-2.p6
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+subset Count of Int where * >= 3;
+
+#| Generates a single row of the triangle.
+multi sub generate-row(Int $n) {
+ my @row = [1];
+
+ for 1..^$n -> $m {
+ my $fr = ($n - $m) / $m;
+ @row.push: @row.tail * $fr;
+ }
+
+ @row;
+}
+
+#| Generate Pascal's Triangle
+sub MAIN(
+ Count :$rows = 3 #= Number of rows to make (minimum 3).
+) {
+ generate-row($_).put for 1..$rows;
+}