From 4a48560dc096968a5dec73a357bc614505ca81e2 Mon Sep 17 00:00:00 2001 From: dmaestro Date: Wed, 17 Apr 2019 22:18:05 -0500 Subject: Solutions to challenge 3 for Doug Schrag (belated) :-( --- challenge-003/doug-schrag/perl6/ch-1.p6 | 22 ++++++++++++++++++++++ challenge-003/doug-schrag/perl6/ch-2.p6 | 6 ++++++ 2 files changed, 28 insertions(+) create mode 100644 challenge-003/doug-schrag/perl6/ch-1.p6 create mode 100644 challenge-003/doug-schrag/perl6/ch-2.p6 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; +} -- cgit