Skip to content

Instantly share code, notes, and snippets.

@gregorym
Created September 24, 2012 20:01
Show Gist options
  • Save gregorym/3778010 to your computer and use it in GitHub Desktop.
Save gregorym/3778010 to your computer and use it in GitHub Desktop.
# Enter your code here. Read input from STDIN. Print output to STDOUT
N = gets.to_i
words = []
while words.length < N do
words << gets.sub(/\\n$/, '').strip
end
words.each do |word|
count = 0
(word.length).times do |i|
sub = word[i..-1]
j=0
while j < sub.length && sub[j] == word[j] do
count += 1
j+=1
end
end
puts count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment