aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-191/simon-proctor/raku/ch-1.raku28
-rw-r--r--challenge-191/simon-proctor/raku/ch-2.raku60
2 files changed, 88 insertions, 0 deletions
diff --git a/challenge-191/simon-proctor/raku/ch-1.raku b/challenge-191/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..69bdfa6e97
--- /dev/null
+++ b/challenge-191/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,28 @@
+#!/usr/bin/env raku
+
+multi sub MAIN ( "TEST" ) is hidden-from-USAGE {
+ use Test;
+ ok ! passes( ( 1,2,3,4 ) );
+ ok passes( ( 1,2,0,5 ) );
+ ok passes( ( 2,6,3,1 ) );
+ ok ! passes( ( 4,5,2,3 ) );
+ ok ! passes( ( |(1..1000000) ) );
+ ok passes( ( |(1..1000000), 2000000 ) );
+ ok passes( ( |(1..500000), 2000000, |(510000..1000000) ) );
+
+ done-testing;
+}
+
+multi sub passes ( @list ) {
+ my @sorted = @list.sort;
+ return @sorted[*-1] >= @sorted[*-2] * 2;
+}
+
+#|( Given a list of ints returns true if the largest element in the list
+ Is at least twice the size of the next largest element
+ Returns True or False)
+multi sub MAIN(
+ *@list where { *.all ~~ IntStr } #= List of ints to check
+) {
+
+}
diff --git a/challenge-191/simon-proctor/raku/ch-2.raku b/challenge-191/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..d6dfe05e9a
--- /dev/null
+++ b/challenge-191/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,60 @@
+#!/usr/bin/env raku
+
+subset ValidRange of Int where 0 < * <= 15;
+subset LargeRange of Int where 9 < * <= 15;
+subset EmptyList of List where *.elems == 0;
+subset NonEmptyList of List where *.elems > 0;
+
+#|( Given an int between 1 and 15 return the number of cute lists can be
+ made from the range 1..$n )
+multi sub MAIN( ValidRange() $n ) {
+ say cute-count( $n );
+}
+
+#|( Prints the list of cute counts for all values between 1 and 15)
+multi sub MAIN() {
+ for ( 1..15 ) {
+ say "$_ : {cute-count($_)}";
+ }
+}
+
+multi sub MAIN( "TEST" ) is hidden-from-USAGE {
+ use Test;
+ is cute-count(2), 2;
+ is cute-count(3), 3;
+ is cute-count(4), 8;
+ is cute-count(5), 10;
+ is cute-count(10), 700;
+ done-testing;
+}
+
+multi sub cute-count( ValidRange $n ) {
+ my @list = 1..$n;
+ if ( $n >= 10 ) {
+ return [+] ( ^@list ).hyper.map( {
+ possible-cute( 1, @list[$_], (|@list[0..$_-1], |@list[$_+1..*]) );
+ });
+ } else {
+ return [+] ( ^@list ).map( {
+ possible-cute( 1, @list[$_], (|@list[0..$_-1], |@list[$_+1..*]) );
+ });
+ }
+}
+
+multi sub possible-cute( $idx is copy, $val is copy, @rest ) {
+ return 0 unless $idx %% $val || $val %% $idx;
+ my $next = $idx+1;
+ if ( @rest.elems > 10 ) {
+ return [+] ( ^(@rest.elems) ).hyper.map( {
+ possible-cute( $next, @rest[$_], (|@rest[0..$_-1], |@rest[$_+1..*]) )
+ });
+ } elsif ( @rest.elems ) {
+ return [+] ( ^(@rest.elems) ).map( {
+ possible-cute( $next, @rest[$_], (|@rest[0..$_-1], |@rest[$_+1..*]) )
+ });
+ }
+ return 1;
+}
+
+
+