aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2020-10-09 15:59:10 +0200
committerLubos Kolouch <lubos@kolouch.net>2020-10-09 15:59:10 +0200
commit92ec88f28334de0e18d3bbeaf314b170078cf475 (patch)
tree5b73491c4e6783ecc2ff14eb0c8acbf11945d6c5
parentde6bd836702f7165f9a03ba643c94b8a6f84f3f1 (diff)
downloadperlweeklychallenge-club-92ec88f28334de0e18d3bbeaf314b170078cf475.tar.gz
perlweeklychallenge-club-92ec88f28334de0e18d3bbeaf314b170078cf475.tar.bz2
perlweeklychallenge-club-92ec88f28334de0e18d3bbeaf314b170078cf475.zip
Python solution Task 1 LK
-rw-r--r--challenge-081/lubos-kolouch/perl/ch-1.pl8
-rw-r--r--challenge-081/lubos-kolouch/python/ch-1.py36
2 files changed, 37 insertions, 7 deletions
diff --git a/challenge-081/lubos-kolouch/perl/ch-1.pl b/challenge-081/lubos-kolouch/perl/ch-1.pl
index 9890053c01..fe05fd99fd 100644
--- a/challenge-081/lubos-kolouch/perl/ch-1.pl
+++ b/challenge-081/lubos-kolouch/perl/ch-1.pl
@@ -9,15 +9,9 @@
# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
# Task 1 - Common base string
#
-# OPTIONS: ---
-# REQUIREMENTS: ---
-# BUGS: ---
-# NOTES: ---
-# AUTHOR: YOUR NAME (),
-# ORGANIZATION:
+# AUTHOR: Lubos Kolouch
# VERSION: 1.0
# CREATED: 10/09/2020 10:43:10 AM
-# REVISION: ---
#===============================================================================
use strict;
diff --git a/challenge-081/lubos-kolouch/python/ch-1.py b/challenge-081/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..e3b1b080ce
--- /dev/null
+++ b/challenge-081/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,36 @@
+#!/bin/env python
+""" ===============================================================================
+#
+# FILE: ch-1.py
+#
+# USAGE: ./ch-1.py
+#
+# DESCRIPTION: Perl Weekly Challenge 081
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-081/
+# Task 1 - Common base string
+#
+# AUTHOR: Lubos Kolouch
+# CREATED: 10/09/2020 10:43:10 AM
+#===============================================================================
+"""
+import re
+
+
+def get_common_strings(str1, str2):
+ """ Find and return the common strings """
+
+ result = []
+ res1 = re.match(r'(.*)\1+', str1)
+
+ result.append(res1.group(1))
+
+ res2 = re.match(r'(.*)\1+', str2)
+ if res1.group(1) != res2.group(1):
+ result.append(res2.group(1))
+
+ return result
+
+
+assert get_common_strings('abcdabcd', 'abcdabcdabcdabcd') == ['abcd','abcdabcd']
+assert get_common_strings('aaa', 'aa') == ['a']
+assert get_common_strings('abc', 'aa') == ['','a']