Skip to content

Instantly share code, notes, and snippets.

@lmcardle
Created July 12, 2012 22:51
Show Gist options
  • Save lmcardle/3101622 to your computer and use it in GitHub Desktop.
Save lmcardle/3101622 to your computer and use it in GitHub Desktop.
longest_repeated_substring.rb
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