| author | Christian Urban <urbanc@in.tum.de> | 
| Sun, 02 Sep 2018 23:27:17 +0100 | |
| changeset 555 | 85f4eeefaea5 | 
| parent 474 | 331b2c9e525f | 
| child 558 | c9da2c4586f2 | 
| permissions | -rw-r--r-- | 
| 420 
25bc57b32efa
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
411diff
changeset | 1 | # example provided by Daniel Baldwin | 
| 58 | 2 | |
| 226 
e3c454e31224
updated so that it works with more recent versions of Ruby
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
121diff
changeset | 3 | nums = (1..1000) | 
| 57 | 4 | |
| 474 | 5 | #iterate through the nums 1-1000 | 
| 57 | 6 | nums.each do |i| | 
| 7 | ||
| 8 | start_time = Time.now | |
| 9 | string = "a" * i | |
| 474 | 10 | |
| 11 | #create a new regular expression based on current value of i | |
| 226 
e3c454e31224
updated so that it works with more recent versions of Ruby
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
121diff
changeset | 12 | re_str = "a?" * i + "+" + "a" * i | 
| 
e3c454e31224
updated so that it works with more recent versions of Ruby
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
121diff
changeset | 13 | re = Regexp.new(re_str) | 
| 57 | 14 | |
| 60 | 15 | re.match(string) | 
| 474 | 16 | |
| 17 | #if re.match(string) | |
| 60 | 18 | 	#	puts "matched string  a * #{i} with regex #{re}"
 | 
| 19 | #else | |
| 20 | 	#	puts "unmatched string a * #{i} with regex #{re}"
 | |
| 21 | #end | |
| 57 | 22 | |
| 60 | 23 |   puts "#{i} %.5f" % (Time.now - start_time)
 | 
| 57 | 24 | end |