diff options
| author | Abigail <abigail@abigail.be> | 2020-10-11 14:06:07 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2020-10-11 14:06:07 +0200 |
| commit | 324bcc1de2a7f771da7b70cdaef60403936adc4a (patch) | |
| tree | 56d8c4aebd117d2216be24cb4ab96d6626d76733 | |
| parent | 4349abc09357350a8212f95e27c3000aee78adbc (diff) | |
| download | perlweeklychallenge-club-324bcc1de2a7f771da7b70cdaef60403936adc4a.tar.gz perlweeklychallenge-club-324bcc1de2a7f771da7b70cdaef60403936adc4a.tar.bz2 perlweeklychallenge-club-324bcc1de2a7f771da7b70cdaef60403936adc4a.zip | |
Perl solution week 81/part 1.
| -rw-r--r-- | challenge-081/abigail/input-1-1 | 2 | ||||
| -rw-r--r-- | challenge-081/abigail/input-1-2 | 2 | ||||
| -rw-r--r-- | challenge-081/abigail/output-1-1.exp | 2 | ||||
| -rw-r--r-- | challenge-081/abigail/output-1-2.exp | 1 | ||||
| -rw-r--r-- | challenge-081/abigail/perl/ch-1.pl | 37 |
5 files changed, 44 insertions, 0 deletions
diff --git a/challenge-081/abigail/input-1-1 b/challenge-081/abigail/input-1-1 new file mode 100644 index 0000000000..bcb118a7c2 --- /dev/null +++ b/challenge-081/abigail/input-1-1 @@ -0,0 +1,2 @@ +abcdabcd +abcdabcdabcdabcd diff --git a/challenge-081/abigail/input-1-2 b/challenge-081/abigail/input-1-2 new file mode 100644 index 0000000000..0917019ba6 --- /dev/null +++ b/challenge-081/abigail/input-1-2 @@ -0,0 +1,2 @@ +aaa +aa diff --git a/challenge-081/abigail/output-1-1.exp b/challenge-081/abigail/output-1-1.exp new file mode 100644 index 0000000000..ddf5cedb9f --- /dev/null +++ b/challenge-081/abigail/output-1-1.exp @@ -0,0 +1,2 @@ +abcdabcd +abcd diff --git a/challenge-081/abigail/output-1-2.exp b/challenge-081/abigail/output-1-2.exp new file mode 100644 index 0000000000..7898192261 --- /dev/null +++ b/challenge-081/abigail/output-1-2.exp @@ -0,0 +1 @@ +a diff --git a/challenge-081/abigail/perl/ch-1.pl b/challenge-081/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..840fc865f9 --- /dev/null +++ b/challenge-081/abigail/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +chomp (my $str1 = <>); +chomp (my $str2 = <>); + +# +# Sort the strings by lenght, so $str1 isn't longer than $str2. +# +($str1, $str2) = ($str2, $str1) if length $str2 < length $str1; + +# +# Find a substring which cannot be part of either string, +# nor of its concatenation. +# +my $sep = "\x00" x (1 + length ($str1) + length ($str2)); + +# +# Now, use a regular expression to find common base strings. +# +$_ = "$str1$sep$str2"; +/^ (.+) \1* # Find base strings of $str1 + $sep # Match the separator + \1+ $ # Must be base string for $str2 + (?{say $1}) # Print it + (*FAIL) # Backtrack so we can try other base strings. +/x; + +__END__ |
