author | Christian Urban <christian.urban@kcl.ac.uk> |
Mon, 27 Jul 2020 11:02:48 +0100 | |
changeset 741 | e66bd5c563eb |
parent 538 | progs/catastrophic2.py@17acdd516ccd |
child 742 | b5b5583a3a08 |
permissions | -rwxr-xr-x |
448 | 1 |
#!/usr/bin/env python |
2 |
import re |
|
3 |
import sys |
|
4 |
||
5 |
# case of catastrophic backtracking in Python |
|
6 |
# |
|
7 |
# regex: (a*)*b |
|
8 |
# strings: aa...a |
|
9 |
# |
|
10 |
# call with timing as: |
|
11 |
# |
|
12 |
# > time ./catastrophic.py 20 |
|
13 |
||
14 |
# counter n given on the command line |
|
15 |
cn = sys.argv[1] |
|
16 |
||
17 |
# calling the matching function |
|
538 | 18 |
s = ("a" * int(cn)) |
19 |
m = re.match('(a*)*b' , s) |
|
448 | 20 |
|
538 | 21 |
print s |