aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-04-14 17:47:37 +0100
committerGitHub <noreply@github.com>2019-04-14 17:47:37 +0100
commit0c0b05fb7c8783f550d44d19c0582021dc7e02db (patch)
tree28adfeb61d1453153adedff09ba2190922e0f3dc
parente28817867e324fe0325db382aa0a6c37040ad353 (diff)
parent01defbf5c53be4bf6a99de1ebe254bc1920cf3ca (diff)
downloadperlweeklychallenge-club-0c0b05fb7c8783f550d44d19c0582021dc7e02db.tar.gz
perlweeklychallenge-club-0c0b05fb7c8783f550d44d19c0582021dc7e02db.tar.bz2
perlweeklychallenge-club-0c0b05fb7c8783f550d44d19c0582021dc7e02db.zip
Merge pull request #52 from jmaslak/jmaslak-week3
Add Perl6 solutions for Week 3
-rw-r--r--challenge-003/joelle-maslak/perl6/ch-1.p618
-rw-r--r--challenge-003/joelle-maslak/perl6/ch-2.p622
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-003/joelle-maslak/perl6/ch-1.p6 b/challenge-003/joelle-maslak/perl6/ch-1.p6
new file mode 100644
index 0000000000..d9649489c7
--- /dev/null
+++ b/challenge-003/joelle-maslak/perl6/ch-1.p6
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+my @hamming = (1..∞).grep: { divisors($^num).grep( *.is-prime ).Set ⊆ (2,3,5).Set };
+say "Hamming numbers [0..4]: " ~ @hamming[^5].join(", ");
+
+sub divisors(Int:D $i -->Array[Int:D]) {
+ if ($i == 0) { return 0; }
+
+ my $sqrt = sqrt($i).Int;
+
+ my Int:D @divs = grep { $i %% $^div }, 1..$sqrt;
+ @divs.append: map { Int($i / $^div) }, @divs;
+
+ return @divs;
+}
+
diff --git a/challenge-003/joelle-maslak/perl6/ch-2.p6 b/challenge-003/joelle-maslak/perl6/ch-2.p6
new file mode 100644
index 0000000000..3200dfc2bf
--- /dev/null
+++ b/challenge-003/joelle-maslak/perl6/ch-2.p6
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+sub MAIN(Int:D $rows where $rows ≥ 3) {
+ my @rows;
+
+ for 0..^($rows) -> $i {
+ my @row;
+ if ! $i {
+ @row = 1;
+ } else {
+ @row.append: 1;
+ @row.append: map { @rows[$i-1][$^a-1] + @rows[$i-1][$^a] }, 1..^$i;
+ @row.append: 1;
+ }
+ @rows.push: @row;
+
+ say (" " x $rows - $i) ~ @row.map( { $^a.fmt("%3d") } ).join(" ");
+ }
+}
+