Created
July 12, 2012 22:51
-
-
Save lmcardle/3101622 to your computer and use it in GitHub Desktop.
longest_repeated_substring.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_time = Time.now | |
match = STDIN.read.scan(/(\w+)\1/) | |
result_length = 0 | |
result = "" | |
match.each do |subarray| | |
subarray.map do |element| | |
if element.length > result_length | |
result_length = element.length | |
result = element | |
end | |
end | |
end | |
puts result | |
puts "Time elapsed #{Time.now - start_time}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment