diff options
| -rw-r--r-- | challenge-003/ohmycloud/perl6/ch-1.p6 | 9 | ||||
| -rw-r--r-- | challenge-003/ohmycloud/perl6/ch-2.p6 | 24 |
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 |
