aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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(" ");
+ }
+}
+