58
|
1 |
# provided by Daniel Baldwin
|
|
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>
diff
changeset
|
3 |
nums = (1..1000)
|
57
|
4 |
|
|
5 |
#iterate through the nums 1-100
|
|
6 |
nums.each do |i|
|
|
7 |
|
|
8 |
start_time = Time.now
|
|
9 |
string = "a" * 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>
diff
changeset
|
10 |
re_str = "a?" * i + "+" + "a" * i
|
57
|
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>
diff
changeset
|
12 |
|
e3c454e31224
updated so that it works with more recent versions of Ruby
Christian Urban <christian dot urban at kcl dot ac dot uk>
diff
changeset
|
13 |
re = Regexp.new(re_str)
|
57
|
14 |
|
60
|
15 |
re.match(string)
|
|
16 |
#if re.match(string)
|
|
17 |
# puts "matched string a * #{i} with regex #{re}"
|
|
18 |
#else
|
|
19 |
# puts "unmatched string a * #{i} with regex #{re}"
|
|
20 |
#end
|
57
|
21 |
|
60
|
22 |
puts "#{i} %.5f" % (Time.now - start_time)
|
57
|
23 |
end
|