Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Created September 6, 2015 06:07
Show Gist options
  • Save oscarmorrison/4d357ffe4081f8434a29 to your computer and use it in GitHub Desktop.
Save oscarmorrison/4d357ffe4081f8434a29 to your computer and use it in GitHub Desktop.
Brute Force String Pattern matching in Ruby
sentence = "soijasdoijasdiojfuhfuhsdfhoscaroijasdoijasdijd"
n = sentence.length
key = "oscar"
l = key.length
i = 0
while i < n do
j = 0
puts sentence[i]
while j < l && sentence[i] == key[j] do
puts "#{sentence[i]} - #{key[j]}"
if sentence[i]==key[l-1]
puts "Yes"
end
i += 1
j += 1
end
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment