aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/zapwai/python
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2024-09-16 12:02:14 -0400
committerDavid Ferrone <zapwai@gmail.com>2024-09-16 12:02:14 -0400
commit3e3e9530a265cb3f549a3556bb78ffdcb1023650 (patch)
tree0ff6a6be7fb3e633fa486069899c8df2df046785 /challenge-287/zapwai/python
parenteae3cd347219654833096d39e152c603f15e7292 (diff)
downloadperlweeklychallenge-club-3e3e9530a265cb3f549a3556bb78ffdcb1023650.tar.gz
perlweeklychallenge-club-3e3e9530a265cb3f549a3556bb78ffdcb1023650.tar.bz2
perlweeklychallenge-club-3e3e9530a265cb3f549a3556bb78ffdcb1023650.zip
Week 287
Diffstat (limited to 'challenge-287/zapwai/python')
-rw-r--r--challenge-287/zapwai/python/ch-1.py49
-rw-r--r--challenge-287/zapwai/python/ch-2.py35
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)
+