author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 20 Sep 2016 12:13:11 +0100 | |
changeset 420 | 25bc57b32efa |
parent 411 | 1aec0e1fda86 |
child 474 | 4bdf0dedd708 |
permissions | -rw-r--r-- |
420
25bc57b32efa
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
411
diff
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:
121
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>
parents:
121
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>
parents:
121
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>
parents:
121
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 |