diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-04-09 14:33:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-09 14:33:05 +0100 |
| commit | b327a3413acd043be4ee46622ed1fd32bcfa9ca8 (patch) | |
| tree | 1755e0c325aa01e1e9e959960a493a7e2c88da32 | |
| parent | 51fdf3add92b0bd722958e593614ba533e7dfbad (diff) | |
| parent | 3441fdde915ce5e0cc46b5b197facce50acdb275 (diff) | |
| download | perlweeklychallenge-club-b327a3413acd043be4ee46622ed1fd32bcfa9ca8.tar.gz perlweeklychallenge-club-b327a3413acd043be4ee46622ed1fd32bcfa9ca8.tar.bz2 perlweeklychallenge-club-b327a3413acd043be4ee46622ed1fd32bcfa9ca8.zip | |
Merge pull request #38 from ohmycloud/master
Challenge-003 solution
| -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 |
