aboutsummaryrefslogtreecommitdiff
path: root/challenge-042/burkhard-nickels/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-01-11 09:46:54 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-01-11 09:46:54 +0000
commita56426175505a28f0cf131f3bb668cfd87d16dff (patch)
tree0d2c4a3a0fac0bdf54b31ffdf88e247769bb38d8 /challenge-042/burkhard-nickels/python
parente017529000f00977b2e35019ff7aa5a7a4ce8b2b (diff)
downloadperlweeklychallenge-club-a56426175505a28f0cf131f3bb668cfd87d16dff.tar.gz
perlweeklychallenge-club-a56426175505a28f0cf131f3bb668cfd87d16dff.tar.bz2
perlweeklychallenge-club-a56426175505a28f0cf131f3bb668cfd87d16dff.zip
- Added solutions by Burkhard Nickels.
Diffstat (limited to 'challenge-042/burkhard-nickels/python')
-rwxr-xr-xchallenge-042/burkhard-nickels/python/ch-1.py19
-rwxr-xr-xchallenge-042/burkhard-nickels/python/ch-2.py38
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-042/burkhard-nickels/python/ch-1.py b/challenge-042/burkhard-nickels/python/ch-1.py
new file mode 100755
index 0000000000..40388def78
--- /dev/null
+++ b/challenge-042/burkhard-nickels/python/ch-1.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import array as arr
+
+print "ch-1.py (Version 1.0) PWC #42 Task #1: Octal numbers."
+
+for i in range(0,50):
+ print "Decimal: ", i, " - Octal: ", oct(i)
+
+
+def print_string(n):
+ buf = "Decimal: %d, Octal: %o" % (n, n)
+ return buf
+
+a = list(range(0,50))
+x = map(print_string, a)
+# print(list(x))
+for e in x: print e
+
diff --git a/challenge-042/burkhard-nickels/python/ch-2.py b/challenge-042/burkhard-nickels/python/ch-2.py
new file mode 100755
index 0000000000..a52447f036
--- /dev/null
+++ b/challenge-042/burkhard-nickels/python/ch-2.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import array as arr
+import re
+import random
+
+print "ch-2.pl (Version 1.0) PWC #42 Task #2: Balanced Brackets\n";
+
+def create_brackets(nr):
+ s = ""
+ for i in range(1,nr):
+ br = random.randint(0,1)
+ if br: s += ")"
+ else : s += "("
+ return s
+
+def balanced_brackets(brs):
+ brs, found = re.subn('\(\)','',brs);
+ ok = 0
+ if found:
+ ok = balanced_brackets(brs)
+ return ok
+ else:
+ if re.search('\(|\)',brs): return 0
+ else: return 1
+
+loops = 0
+while True:
+ loops = loops + 1
+ nr = random.randint(2,10)
+ brs = create_brackets(nr)
+ ok = balanced_brackets(brs)
+ rs = "NOT OK"
+ if ok: rs = "OK"
+ print("(%2d) %10s = %s" % (loops, brs, rs))
+ if ok: break
+ if loops > 20: break
+