From 3e3e9530a265cb3f549a3556bb78ffdcb1023650 Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 16 Sep 2024 12:02:14 -0400 Subject: Week 287 --- challenge-287/zapwai/python/ch-1.py | 49 +++++++++++++++++++++++++++++++++++++ challenge-287/zapwai/python/ch-2.py | 35 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 challenge-287/zapwai/python/ch-1.py create mode 100644 challenge-287/zapwai/python/ch-2.py (limited to 'challenge-287/zapwai/python') 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) + -- cgit