diff options
| author | dmaestro <dmaestro@cpan.org> | 2019-04-17 22:18:05 -0500 |
|---|---|---|
| committer | dmaestro <dmaestro@cpan.org> | 2019-04-18 07:57:57 -0500 |
| commit | 4a48560dc096968a5dec73a357bc614505ca81e2 (patch) | |
| tree | 2e9b07fc8bdeca00030eb8d33a5a7a264fdf840b | |
| parent | d3c944ec0fe23bfe26f8167b9bf21d5de2dfd0fe (diff) | |
| download | perlweeklychallenge-club-4a48560dc096968a5dec73a357bc614505ca81e2.tar.gz perlweeklychallenge-club-4a48560dc096968a5dec73a357bc614505ca81e2.tar.bz2 perlweeklychallenge-club-4a48560dc096968a5dec73a357bc614505ca81e2.zip | |
Solutions to challenge 3 for Doug Schrag
(belated) :-(
| -rw-r--r-- | challenge-003/doug-schrag/perl6/ch-1.p6 | 22 | ||||
| -rw-r--r-- | challenge-003/doug-schrag/perl6/ch-2.p6 | 6 |
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-003/doug-schrag/perl6/ch-1.p6 b/challenge-003/doug-schrag/perl6/ch-1.p6 new file mode 100644 index 0000000000..c16f56f8fc --- /dev/null +++ b/challenge-003/doug-schrag/perl6/ch-1.p6 @@ -0,0 +1,22 @@ +use v6; + +sub MAIN(Int :$limit = 9) { + # Use Slip() to flatten the list just one level + my @exponents-list = (^$limit).produce(&grow) + .map({ Slip( $_ ?? $_ !! () ) }); + # 3D coordinates used as powers of the allowable + # prime factors + for @exponents-list { + # @() is used to indicate multiple element in the + # argument list to the Z operator (also below) + say [*] (2, 3, 5) Z** @($_) + } +} + +multi sub grow (Int, Int) { ((0, 0, 0),) } +multi sub grow (List $a, Int $b --> List()) { + # Sequence of integral points in 3D space where sum + # of coordinates is the next integer (0, 1, 2 ...) + ( @($a) XZ+ (1, 0, 0), (0, 1, 0), (0, 0, 1) ) + .map(*.List).unique(:with(&[eqv])); +} diff --git a/challenge-003/doug-schrag/perl6/ch-2.p6 b/challenge-003/doug-schrag/perl6/ch-2.p6 new file mode 100644 index 0000000000..cd8b8b9c48 --- /dev/null +++ b/challenge-003/doug-schrag/perl6/ch-2.p6 @@ -0,0 +1,6 @@ +use v6; + +sub MAIN (Int :$size = 10) { + say .join(" ") + for (1,), { |$_, 0 Z+ 0, |$_ } ... *.elems == $size; +} |
