# HG changeset patch # User Christian Urban # Date 1537783539 -3600 # Node ID 447ed6c7cdad781a0b8fda70da9c92649a040a25 # Parent 9ab8a6fc58c0cf570f4c7cf65e6212d4b92ec948 updated diff -r 9ab8a6fc58c0 -r 447ed6c7cdad 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 9ab8a6fc58c0 -r 447ed6c7cdad 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 9ab8a6fc58c0 -r 447ed6c7cdad 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)