From 3e2f724548509a62b8df3ba8eb6d4320c836018c Mon Sep 17 00:00:00 2001 From: Alexander <39702500+threadless-screw@users.noreply.github.com> Date: Sun, 16 Jun 2019 10:57:44 +0200 Subject: Create ch-2.p6 --- challenge-012/ozzy/perl6/ch-2.p6 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-012/ozzy/perl6/ch-2.p6 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 = ""; # 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; +} -- cgit