progs/catastrophic.rb
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 04 Oct 2016 12:00:23 +0100
changeset 440 e14cd32ad497
parent 420 25bc57b32efa
child 474 4bdf0dedd708
permissions -rw-r--r--
updated

# example provided by Daniel Baldwin

nums = (1..1000)

#iterate through the nums 1-100
nums.each do |i|

	start_time = Time.now
	string = "a" * i
	re_str = "a?" * i + "+" + "a" * i
	#create a new regular expression based on current value of i
	
	re = Regexp.new(re_str)

        re.match(string)
	#if re.match(string)
	#	puts "matched string  a * #{i} with regex #{re}"
	#else
	#	puts "unmatched string a * #{i} with regex #{re}"
	#end
	
  puts "#{i} %.5f" % (Time.now - start_time)
end