Skip to content

Instantly share code, notes, and snippets.

@abishekk92
Created May 19, 2012 18:27
Show Gist options
  • Save abishekk92/2731833 to your computer and use it in GitHub Desktop.
Save abishekk92/2731833 to your computer and use it in GitHub Desktop.
Solution to InterviewStreet String Finding
# To change this template, choose Tools | Templates
# and open the template in the editor.
input_limit=gets
limit=input_limit.to_i
inputs=[]
result=0
def compute_result(string1,sub_string)
answer=0
string1_array=string1.each_char.to_a
sub_string_array=sub_string.each_char.to_a
for index in 0..string1_array.length
if string1_array[index]==sub_string_array[index]
answer+=1
else
return answer
end
end
end
until limit == 0
inputs.push(gets)
limit=limit-1
end
for i in 0..inputs.length-1
sum=0
for j in 0..inputs[i].to_s.length-2
char=inputs[i].to_s.slice(j..inputs[i].to_s.length-2)
result=compute_result(inputs[i].to_s,char)
sum+=result
end
puts "#{sum}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment