aboutsummaryrefslogtreecommitdiff
path: root/challenge-051
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-051')
-rw-r--r--challenge-051/markus-holzer/ch-2.p618
1 files changed, 11 insertions, 7 deletions
diff --git a/challenge-051/markus-holzer/ch-2.p6 b/challenge-051/markus-holzer/ch-2.p6
index e8b4096159..70870b59eb 100644
--- a/challenge-051/markus-holzer/ch-2.p6
+++ b/challenge-051/markus-holzer/ch-2.p6
@@ -1,10 +1,11 @@
use Terminal::ANSIColor;
+use Terminal::Table;
sub MAIN( Int $from, Int $to, Bool :$only = False )
{
my @colors = <red green yellow blue magenta cyan>;
- print "$_," for gather for $from..$to -> $n
+ print "$_, " for gather for $from..$to -> $n
{
my @subsets = consecutive-combinations( $n.comb );
my @products = @subsets.map({ [*] $_ });
@@ -13,17 +14,14 @@ sub MAIN( Int $from, Int $to, Bool :$only = False )
take color($color) ~ $n ~ color('reset')
if $colorful or !$only;
- };
+ }
}
sub consecutive-combinations( @n )
{
- my sub keys-of( @p ) { @p.map: *.key }
- my sub values-of( @p ) { @p.map: *.value }
-
- my multi sub is-consecutive( $a, $b ) { $a + 1 == $b }
- my multi sub is-consecutive( @n ) { @n.elems == 1 or [[&is-consecutive]] @n }
+ my sub keys-of( @p ) { @p.map: *.key }
+ my sub values-of( @p ) { @p.map: *.value }
@n
.pairs
@@ -33,6 +31,12 @@ sub consecutive-combinations( @n )
;
}
+my sub is-consecutive( @n )
+{
+ @n.elems == 1
+ or
+ not @n.rotor(2 => -1).first({ .[0] + 1 == .[1] })
+}