diff options
Diffstat (limited to 'challenge-012/simon-proctor')
| -rw-r--r-- | challenge-012/simon-proctor/README | 1 | ||||
| -rw-r--r-- | challenge-012/simon-proctor/perl6/ch-1.p6 | 11 | ||||
| -rwxr-xr-x | challenge-012/simon-proctor/perl6/ch-2.p6 | 24 |
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-012/simon-proctor/README b/challenge-012/simon-proctor/README new file mode 100644 index 0000000000..f674742166 --- /dev/null +++ b/challenge-012/simon-proctor/README @@ -0,0 +1 @@ +Solution by Simon Proctor diff --git a/challenge-012/simon-proctor/perl6/ch-1.p6 b/challenge-012/simon-proctor/perl6/ch-1.p6 new file mode 100644 index 0000000000..13764275c0 --- /dev/null +++ b/challenge-012/simon-proctor/perl6/ch-1.p6 @@ -0,0 +1,11 @@ +#!/usr/bin/perl6 + +use v6; + +my @primes = (1...*).grep(*.is-prime); + +my @euclid = (0...*).map( -> $i { ( [*] @primes[0..$i] ) + 1 } ); + +my @non-prime-euclid = @euclid.grep( ! *.is-prime ); + +say @non-prime-euclid[0]; diff --git a/challenge-012/simon-proctor/perl6/ch-2.p6 b/challenge-012/simon-proctor/perl6/ch-2.p6 new file mode 100755 index 0000000000..22170940f4 --- /dev/null +++ b/challenge-012/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,24 @@ +#!/usr/bin/perl6 + +use v6; + +my %*SUB-MAIN-OPTS = :named-anywhere; + +multi sub MAIN is hidden-from-USAGE { + say $*USAGE; +} + +#| Given a list of paths returns the longest shared path between them +multi sub MAIN( + *@paths, #= List of paths to check + :$seperator = $*SPEC.dir-sep #= Optional directory seperator. Defaults to the system standard. +) { + my @checks = @paths.sort( { $^b.codes <=> $^a.codes } )[0].split($seperator)[1..*-2]; + my $path = $seperator; + my $new-path = $path; + while ( all( @paths ) ~~ / ^ $new-path / ) { + $path = $new-path; + $new-path ~= ( @checks.shift ~ $seperator ); + }; + say $path; +} |
