progs/catastrophic.rb
changeset 474 4bdf0dedd708
parent 420 25bc57b32efa
child 558 447ed6c7cdad
equal deleted inserted replaced
473:dc528091eb70 474:4bdf0dedd708
     1 # example provided by Daniel Baldwin
     1 # example provided by Daniel Baldwin
     2 
     2 
     3 nums = (1..1000)
     3 nums = (1..1000)
     4 
     4 
     5 #iterate through the nums 1-100
     5 #iterate through the nums 1-1000
     6 nums.each do |i|
     6 nums.each do |i|
     7 
     7 
     8 	start_time = Time.now
     8 	start_time = Time.now
     9 	string = "a" * i
     9 	string = "a" * i
       
    10 
       
    11         #create a new regular expression based on current value of i
    10 	re_str = "a?" * i + "+" + "a" * i
    12 	re_str = "a?" * i + "+" + "a" * i
    11 	#create a new regular expression based on current value of i
       
    12 	
       
    13 	re = Regexp.new(re_str)
    13 	re = Regexp.new(re_str)
    14 
    14 
    15         re.match(string)
    15         re.match(string)
    16 	#if re.match(string)
    16 
       
    17         #if re.match(string)
    17 	#	puts "matched string  a * #{i} with regex #{re}"
    18 	#	puts "matched string  a * #{i} with regex #{re}"
    18 	#else
    19 	#else
    19 	#	puts "unmatched string a * #{i} with regex #{re}"
    20 	#	puts "unmatched string a * #{i} with regex #{re}"
    20 	#end
    21 	#end
    21 	
    22