updated
authorChristian Urban <urbanc@in.tum.de>
Thu, 29 Nov 2018 02:18:05 +0000
changeset 613 bfd511b7ecbf
parent 612 7a12053567d4
child 614 be065677c8f1
updated
progs/catastrophic.py
--- a/progs/catastrophic.py	Wed Nov 28 23:45:37 2018 +0000
+++ b/progs/catastrophic.py	Thu Nov 29 02:18:05 2018 +0000
@@ -2,34 +2,20 @@
 import re
 import sys
 
-# A case of catastrophic backtracking in Python
-#
-# regex: (a?){n} a{n}
-# strings: aa...
-#
-# call with:
+# case of catastrophic backtracking in Python
 #
-#   > ./catastrophic.py 20
-#
-# or
-#
-#   > ./catastrophic.py 28
-#
+# regex: (a*)*b
+# strings: aa...a
 #
 # call with timing as:
 #
 #   > time ./catastrophic.py 20
 
-
-
 # counter n given on the command line
 cn = sys.argv[1]
 
-# constructing the regex
-r1 = '((a?){%s})' % cn
-r2 = 'a{%s}' % cn
+# calling the matching function
+s = ("a" * int(cn))
+m = re.match('(a*)*b' , s) 
 
-# calling the matching function
-m = re.match(r1 + r2 , "a" * int(cn)) 
-
-print m.group(0)
+print s