diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-16 20:22:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-16 20:22:45 +0100 |
| commit | 6ba96d45227883a88bec4e91870d341e097ca8d1 (patch) | |
| tree | 77e38d414aaea777fa5f89cdd1c3837c8f759ad6 /challenge-287/zapwai/python | |
| parent | 7211ba649cbe1119acfa16d7fa942f70e3b2759d (diff) | |
| parent | 3e3e9530a265cb3f549a3556bb78ffdcb1023650 (diff) | |
| download | perlweeklychallenge-club-6ba96d45227883a88bec4e91870d341e097ca8d1.tar.gz perlweeklychallenge-club-6ba96d45227883a88bec4e91870d341e097ca8d1.tar.bz2 perlweeklychallenge-club-6ba96d45227883a88bec4e91870d341e097ca8d1.zip | |
Merge pull request #10852 from zapwai/branch-for-287
Week 287
Diffstat (limited to 'challenge-287/zapwai/python')
| -rw-r--r-- | challenge-287/zapwai/python/ch-1.py | 49 | ||||
| -rw-r--r-- | challenge-287/zapwai/python/ch-2.py | 35 |
2 files changed, 84 insertions, 0 deletions
diff --git a/challenge-287/zapwai/python/ch-1.py b/challenge-287/zapwai/python/ch-1.py new file mode 100644 index 0000000000..d3764062d6 --- /dev/null +++ b/challenge-287/zapwai/python/ch-1.py @@ -0,0 +1,49 @@ +import re +def proc(mystr) : + print( "Input:", mystr) + mylen = len( mystr ) + len_diff = 0 + if mylen < 6: + len_diff = 6 - mylen + elif mylen > 20: + len_diff = mylen - 20 + l = list(mystr) + lengths = [] + hits = 0 + for i in range(mylen - 1): + if l[i] == l[i+1]: + hits += 1 + else : + if hits > 1 : + lengths.append(1+hits) + hits = 0 + if hits > 1 : + lengths.append(1+hits) + steps = 0 + for l in lengths : + steps += int(l/3) + lflag = 1 + uflag = 1 + dflag = 1 + if re.search('[a-z]',mystr): + lflag = 0 + if re.search('[A-Z]',mystr): + uflag = 0 + if re.search('\d',mystr): + dflag = 0 + tally = lflag + uflag + dflag + out_val = len_diff + steps + if out_val < tally : + out_val += tally - out_val + print( "Output: ", out_val) + +mystr = "a" +proc(mystr) +mystr = "aB2" +proc(mystr) +mystr = "PaaSW0rd" +proc(mystr) +mystr = "turbbbbot" +proc(mystr) +mystr = "111" +proc(mystr) diff --git a/challenge-287/zapwai/python/ch-2.py b/challenge-287/zapwai/python/ch-2.py new file mode 100644 index 0000000000..867df4f639 --- /dev/null +++ b/challenge-287/zapwai/python/ch-2.py @@ -0,0 +1,35 @@ +import re +def proc(mystr) : + print("Input:", mystr) + output = "False" + p = mystr.split(".") + if len(p) == 1 : + if re.search('^\d+$', mystr): + output = "True" + elif re.search('^\d+e\d+$|^\d+E\d+$', mystr): + output = "True" + elif len(p) == 2: + if re.search('^\d+$', p[0]) and re.search('^\d+$', p[1]): + output = "True" + elif re.search('^\d+$', p[0]) and re.search('^\d+e\d+$|^\d+E\d+$', p[1]): + output = "True" + + print("Output:", output) + +mystr = "1" +proc(mystr) +mystr = "56e10" +proc(mystr) +mystr = "2E32" +proc(mystr) +mystr = "a" +proc(mystr) +mystr = "1.2" +proc(mystr) +mystr = "1.2.6" +proc(mystr) +mystr = "3.142e10" +proc(mystr) +mystr = "3.142e42B" +proc(mystr) + |
