aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-04-14 11:32:14 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-04-14 11:32:14 +0100
commitada267d92125c0532e070686e241ef0b14497321 (patch)
treec7f1405e6c4a662068bc358e8e23f808ad9ba6fb
parentabc861ee3d022271401c9cd2ba1bcd87b9f1e248 (diff)
downloadperlweeklychallenge-club-ada267d92125c0532e070686e241ef0b14497321.tar.gz
perlweeklychallenge-club-ada267d92125c0532e070686e241ef0b14497321.tar.bz2
perlweeklychallenge-club-ada267d92125c0532e070686e241ef0b14497321.zip
- Added solution by Mark Senn.
-rw-r--r--challenge-003/mark-senn/blog.txt1
-rw-r--r--challenge-003/mark-senn/perl6/ch-1.p613
-rw-r--r--challenge-003/mark-senn/perl6/ch-2.p655
3 files changed, 69 insertions, 0 deletions
diff --git a/challenge-003/mark-senn/blog.txt b/challenge-003/mark-senn/blog.txt
new file mode 100644
index 0000000000..f3851d3c24
--- /dev/null
+++ b/challenge-003/mark-senn/blog.txt
@@ -0,0 +1 @@
+http://bit.ly/pwc-003
diff --git a/challenge-003/mark-senn/perl6/ch-1.p6 b/challenge-003/mark-senn/perl6/ch-1.p6
new file mode 100644
index 0000000000..ed581f6b18
--- /dev/null
+++ b/challenge-003/mark-senn/perl6/ch-1.p6
@@ -0,0 +1,13 @@
+# Perl Weekly Challenge - 003
+# Challenge #1
+#
+# See
+# http://bit.ly/pwc-003
+# for more information.
+
+# Run using Perl 6.
+use v6;
+
+my @prime = (2, 3, 5);
+my @product = @prime <<*>> @prime;
+@product.join("\n").say;
diff --git a/challenge-003/mark-senn/perl6/ch-2.p6 b/challenge-003/mark-senn/perl6/ch-2.p6
new file mode 100644
index 0000000000..83c3a12299
--- /dev/null
+++ b/challenge-003/mark-senn/perl6/ch-2.p6
@@ -0,0 +1,55 @@
+# Perl Weekly Challenge - 003
+# Challenge #2
+#
+# See
+# http://bit.ly/pwc-003
+# for more information.
+
+# Run using Perl 6.
+use v6;
+
+sub MAIN(Int $y where * >= 3)
+{
+ my $x = ($y/2).floor;
+
+ my $max-value = binom($y, $x);
+ my $w = $max-value.chars;
+
+ for (0..$y) -> $n
+ {
+ # Start each row with ($y-$n) * (1+$w) spaces followed by a 1.
+ print ' ' x ($y-$n) * (1+$w);
+ print '1';
+
+ # Each subsequent column should be
+ # o prefixed by a space
+ # o followed by $w spaces (for the missing number in that column)
+ # o followed by another space
+ # o followed by the column value right-justified in a field $w characters wide
+ for (1..$n) -> $k
+ {
+ print ' ';
+ print ' ' x $w;
+ print ' ';
+ printf "%{$w}d", binom($n,$k);
+ }
+ print "\n";
+ }
+}
+
+sub binom($n, $k)
+{
+ fact($n) / (fact($k) * fact($n-$k))
+}
+
+sub fact($n)
+{
+ ($n == 0)
+ ?? 1
+ !! [*] (1..$n)
+}
+
+sub USAGE()
+{
+ note "usage: perl6 {$*PROGRAM-NAME} non-negative_integer_of_at_least_three";
+}