re-internal.rb
author Christian Urban <urbanc@in.tum.de>
Mon, 05 Nov 2012 20:27:58 +0000
changeset 57 0c96b2c04591
child 58 f516892da470
permissions -rw-r--r--
added ruby version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
nums = (1..100)
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
#iterate through the nums 1-100
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
nums.each do |i|
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
	start_time = Time.now
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
	string = "a" * i
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
	#create a new regular expression based on current value of i
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
	re = Regexp.new(/((a?){#{i}})(a{#{i}})/)
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
	if re.match(string)
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
		puts "matched string  a * #{i} with regex #{re}"
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
	else
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
		puts "unmatched string a * #{i} with regex #{re}"
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
	end
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
	
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
	puts "in = #{(Time.now - start_time) * 1000} milliseconds"
0c96b2c04591 added ruby version
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
end