diff options
| author | Alexander <39702500+threadless-screw@users.noreply.github.com> | 2019-06-16 10:57:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-16 10:57:44 +0200 |
| commit | 3e2f724548509a62b8df3ba8eb6d4320c836018c (patch) | |
| tree | 95d02715d58a27909bcc325b4fe950ec729e2a1e | |
| parent | 68c7efea59f5e107c27305a8a084ca1b88867022 (diff) | |
| download | perlweeklychallenge-club-3e2f724548509a62b8df3ba8eb6d4320c836018c.tar.gz perlweeklychallenge-club-3e2f724548509a62b8df3ba8eb6d4320c836018c.tar.bz2 perlweeklychallenge-club-3e2f724548509a62b8df3ba8eb6d4320c836018c.zip | |
Create ch-2.p6
| -rw-r--r-- | challenge-012/ozzy/perl6/ch-2.p6 | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-012/ozzy/perl6/ch-2.p6 b/challenge-012/ozzy/perl6/ch-2.p6 new file mode 100644 index 0000000000..f540334a96 --- /dev/null +++ b/challenge-012/ozzy/perl6/ch-2.p6 @@ -0,0 +1,20 @@ +#!/usr/bin/env perl6 + +my @paths = "/a/b/c/d", "/a/b/cd", "/a/b/cc", "/a/b/c/d/e"; # Paths to be tested for commonality +my $M = @paths[0] ~~ / ( .+? \/ )+ /; # Split the 1st path in directories +my $common = "<no common path>"; # Variable holding verified common path + +for 0..$M[0].elems-1 -> $i { # Test progressively longer portions of first path + my $cc = [~] $M[0][0..$i]; #+ for presence in other paths. + if commdir($cc) { $common = $cc } else { last }; # Update verified path on positive verification +} +say $common; # Output final verified common path + + +sub commdir ( $cc ) # Test for the presence of a given commonality +{ #+ candidate extracted from the first path in the + for 1..(@paths.elems-1) -> $j { #+ other paths. + return False if @paths[$j] !~~ /^ $cc /; + } + return True; +} |
