progs/catastrophic.py
changeset 558 447ed6c7cdad
parent 420 25bc57b32efa
child 613 bfd511b7ecbf
equal deleted inserted replaced
557:9ab8a6fc58c0 558:447ed6c7cdad
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 import re
     2 import re
     3 import sys
     3 import sys
     4 
     4 
     5 # case of catastrophic backtracking in Python
     5 # A case of catastrophic backtracking in Python
     6 #
     6 #
     7 # regex: (a?){n} a{n}
     7 # regex: (a?){n} a{n}
     8 # strings: aa...
     8 # strings: aa...
     9 #
     9 #
       
    10 # call with:
       
    11 #
       
    12 #   > ./catastrophic.py 20
       
    13 #
       
    14 # or
       
    15 #
       
    16 #   > ./catastrophic.py 28
       
    17 #
       
    18 #
    10 # call with timing as:
    19 # call with timing as:
    11 #
    20 #
    12 #   > time ./catastrophic.py 20
    21 #   > time ./catastrophic.py 20
       
    22 
       
    23 
    13 
    24 
    14 # counter n given on the command line
    25 # counter n given on the command line
    15 cn = sys.argv[1]
    26 cn = sys.argv[1]
    16 
    27 
    17 # constructing the regex
    28 # constructing the regex