# HG changeset patch # User Christian Urban # Date 1537783539 -3600 # Node ID c9da2c4586f269b185a281301195139262ef71eb # Parent 6d0e8b6f424394d1d0ed2a654fd422dbfcef8cfe updated diff -r 6d0e8b6f4243 -r c9da2c4586f2 progs/catastrophic.java --- a/progs/catastrophic.java Sun Sep 23 09:04:24 2018 +0100 +++ b/progs/catastrophic.java Mon Sep 24 11:05:39 2018 +0100 @@ -1,7 +1,16 @@ -// a case of catastrophic backtracking in Java +// A case of catastrophic backtracking in Java 8 +//----------------------------------------------- // // regexp: (a*)*b // strings: aa.... +// +// compile: javac catastrophic.java +// call with: java catastrophic +// +// IMPORTANT: +// Java 9 improved its regex matching engine. +// This example is now much faster. +// import java.util.regex.*; diff -r 6d0e8b6f4243 -r c9da2c4586f2 progs/catastrophic.py --- a/progs/catastrophic.py Sun Sep 23 09:04:24 2018 +0100 +++ b/progs/catastrophic.py Mon Sep 24 11:05:39 2018 +0100 @@ -2,15 +2,26 @@ import re import sys -# case of catastrophic backtracking in Python +# A case of catastrophic backtracking in Python # # regex: (a?){n} a{n} # strings: aa... # +# call with: +# +# > ./catastrophic.py 20 +# +# or +# +# > ./catastrophic.py 28 +# +# # call with timing as: # # > time ./catastrophic.py 20 + + # counter n given on the command line cn = sys.argv[1] diff -r 6d0e8b6f4243 -r c9da2c4586f2 progs/catastrophic.rb --- a/progs/catastrophic.rb Sun Sep 23 09:04:24 2018 +0100 +++ b/progs/catastrophic.rb Mon Sep 24 11:05:39 2018 +0100 @@ -1,4 +1,15 @@ +# A case of catastrophic backtracking in Ruby +#--------------------------------------------- +# +# regex: (a?){n} a{n} +# strings: aa... +# # example provided by Daniel Baldwin +# +# call with: +# +# > ruby catastrophic.rb +# nums = (1..1000)