diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-17 00:37:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-17 00:37:02 +0100 |
| commit | b13925c0542c4e356e27a04dfd1f305f5e4f0f18 (patch) | |
| tree | 331f8b7068857935ce0608436ae27a554983665a /challenge-321/packy-anderson/python/ch-2.py | |
| parent | 8ec526706ce12f3249b2392009f54125bbcdc11f (diff) | |
| parent | d2d3f658384be159cedb6d4288524a14cfd1d3ea (diff) | |
| download | perlweeklychallenge-club-b13925c0542c4e356e27a04dfd1f305f5e4f0f18.tar.gz perlweeklychallenge-club-b13925c0542c4e356e27a04dfd1f305f5e4f0f18.tar.bz2 perlweeklychallenge-club-b13925c0542c4e356e27a04dfd1f305f5e4f0f18.zip | |
Merge pull request #12030 from packy/master
Challenge 321 solutions by Packy Anderson
Diffstat (limited to 'challenge-321/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-321/packy-anderson/python/ch-2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-321/packy-anderson/python/ch-2.py b/challenge-321/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..e1f1bc7c82 --- /dev/null +++ b/challenge-321/packy-anderson/python/ch-2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import re + +def backspaceCompare(str1, str2): + s1 = re.sub(r'.\#', "", str1) + while s1 != str1: + str1 = s1 + s1 = re.sub(r'.\#', "", str1) + s2 = re.sub(r'.\#', "", str2) + while s2 != str2: + str2 = s2 + s2 = re.sub(r'.\#', "", str2) + return s1 == s2 + +def solution(str1, str2): + print(f'Input: $str1 = "{str1}"') + print(f' $str2 = "{str2}"') + print(f'Output: { backspaceCompare(str1, str2) }') + +print('Example 1:') +solution("ab#c", "ad#c") + +print('\nExample 2:') +solution("ab##", "a#b#") + +print('\nExample 3:') +solution("a#b", "c") |
