From dcd5dc8d7f0e8cec0e329f8abadbdfcc583fdfa3 Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Sun, 14 Apr 2019 14:34:36 -0500 Subject: Allow specifying number count on command line --- challenge-003/joelle-maslak/perl6/ch-1.p6 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) mode change 100644 => 100755 challenge-003/joelle-maslak/perl6/ch-1.p6 diff --git a/challenge-003/joelle-maslak/perl6/ch-1.p6 b/challenge-003/joelle-maslak/perl6/ch-1.p6 old mode 100644 new mode 100755 index d9649489c7..f93e7683ab --- a/challenge-003/joelle-maslak/perl6/ch-1.p6 +++ b/challenge-003/joelle-maslak/perl6/ch-1.p6 @@ -2,8 +2,10 @@ 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 MAIN(Int:D $count where * ≥ 0) { + my @hamming = (1..∞).grep: { divisors($^num).grep( *.is-prime ).Set ⊆ (2,3,5).Set }; + say "Hamming numbers [0..{$count-1}]: " ~ @hamming[^$count].join(", "); +} sub divisors(Int:D $i -->Array[Int:D]) { if ($i == 0) { return 0; } -- cgit