aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorohmycloud <ohmycloudy@gmail.com>2019-04-09 12:34:26 +0800
committerohmycloud <ohmycloudy@gmail.com>2019-04-09 12:34:26 +0800
commit3441fdde915ce5e0cc46b5b197facce50acdb275 (patch)
treed38bd790f746c6fd6420998c3be99ea35da3d433
parent515a39407d03881d9e91d63561d9009681a3d0c6 (diff)
downloadperlweeklychallenge-club-3441fdde915ce5e0cc46b5b197facce50acdb275.tar.gz
perlweeklychallenge-club-3441fdde915ce5e0cc46b5b197facce50acdb275.tar.bz2
perlweeklychallenge-club-3441fdde915ce5e0cc46b5b197facce50acdb275.zip
Change-003 solution
-rw-r--r--challenge-003/ohmycloud/perl6/ch-1.p69
-rw-r--r--challenge-003/ohmycloud/perl6/ch-2.p624
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-003/ohmycloud/perl6/ch-1.p6 b/challenge-003/ohmycloud/perl6/ch-1.p6
new file mode 100644
index 0000000000..a29127d30c
--- /dev/null
+++ b/challenge-003/ohmycloud/perl6/ch-1.p6
@@ -0,0 +1,9 @@
+multi sub pascal (1) { $[1] }
+multi sub pascal (Int $n where 2..*) {
+ my @rows = pascal $n - 1;
+ |@rows, [0, |@rows[*-1] Z+ |@rows[*-1], 0 ];
+}
+
+sub MAIN(Int $row) {
+ .say for pascal $row;
+} \ No newline at end of file
diff --git a/challenge-003/ohmycloud/perl6/ch-2.p6 b/challenge-003/ohmycloud/perl6/ch-2.p6
new file mode 100644
index 0000000000..73fa14704f
--- /dev/null
+++ b/challenge-003/ohmycloud/perl6/ch-2.p6
@@ -0,0 +1,24 @@
+
+sub ugly-number(Int $index) {
+ return 0 if $index == 0;
+ my @baselist = [1];
+ my ($min2, $min3, $min5) = 0,0,0;
+ my $curnum = 1;
+
+ while $curnum < $index {
+ my $minnum = (@baselist[$min2] * 2, @baselist[$min3] * 3, @baselist[$min5] * 5).min;
+ @baselist.append($minnum);
+
+ while @baselist[$min2] * 2 <= $minnum { $min2 += 1 }
+ while @baselist[$min3] * 3 <= $minnum { $min3 += 1 }
+ while @baselist[$min5] * 5 <= $minnum { $min5 += 1 }
+
+ $curnum +=1
+ }
+
+ return @baselist[*-1]
+}
+
+sub MAIN(Int $count) {
+ ugly-number($_).say for 1..$count;
+} \ No newline at end of file