aboutsummaryrefslogtreecommitdiff
path: root/challenge-042/kivanc-yazan/python3/ch-2.py
diff options
context:
space:
mode:
authordrclaw1394 <drclaw@mac.com>2020-01-07 16:30:27 +1000
committerGitHub <noreply@github.com>2020-01-07 16:30:27 +1000
commit896b7ced42b40eb3ee62c38d237d4d07df51f169 (patch)
tree73af7aec5c7a251f6f5030fa9a7e39ae412af123 /challenge-042/kivanc-yazan/python3/ch-2.py
parent7649e23d2b150b36cdd134bcf17125f3b9696ada (diff)
parente015238170e27c690e4f46646b6687f600fd0c59 (diff)
downloadperlweeklychallenge-club-896b7ced42b40eb3ee62c38d237d4d07df51f169.tar.gz
perlweeklychallenge-club-896b7ced42b40eb3ee62c38d237d4d07df51f169.tar.bz2
perlweeklychallenge-club-896b7ced42b40eb3ee62c38d237d4d07df51f169.zip
Merge pull request #41 from manwar/master
Update to w42
Diffstat (limited to 'challenge-042/kivanc-yazan/python3/ch-2.py')
-rwxr-xr-xchallenge-042/kivanc-yazan/python3/ch-2.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-042/kivanc-yazan/python3/ch-2.py b/challenge-042/kivanc-yazan/python3/ch-2.py
new file mode 100755
index 0000000000..8dd3c0169f
--- /dev/null
+++ b/challenge-042/kivanc-yazan/python3/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+import random
+
+# Write a script to generate a string with random number of ( and ) brackets.
+# Then make the script validate the string if it has balanced brackets.
+
+# Let's make sure we have equal number of ( and ) to increase chances
+count = random.randint(1,10) # Could be as low as 1, as high as 10
+chars = [ '(', ')' ] * count
+random.shuffle(chars)
+print(''.join(chars))
+
+# Walk through to validate
+current_open = 0
+for char in chars:
+ if char == '(':
+ current_open += 1
+ elif current_open == 0:
+ print('Not Valid')
+ exit()
+ else:
+ current_open -= 1
+print('Valid')