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