diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-06-16 10:14:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-16 10:14:55 +0100 |
| commit | 5e5c3db266e231dbd93516bc8bdb11191c9f5b83 (patch) | |
| tree | 69b4a0a4c6f3af0bb4f42cc7e0d8d21f79c10bf4 /challenge-012 | |
| parent | a9bc06184a093db576a4b701e923c2100e19c246 (diff) | |
| parent | 3e2f724548509a62b8df3ba8eb6d4320c836018c (diff) | |
| download | perlweeklychallenge-club-5e5c3db266e231dbd93516bc8bdb11191c9f5b83.tar.gz perlweeklychallenge-club-5e5c3db266e231dbd93516bc8bdb11191c9f5b83.tar.bz2 perlweeklychallenge-club-5e5c3db266e231dbd93516bc8bdb11191c9f5b83.zip | |
Merge pull request #260 from threadless-screw/master
Create ch-2.p6
Diffstat (limited to 'challenge-012')
| -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; +} |
