Created
September 6, 2015 06:07
-
-
Save oscarmorrison/4d357ffe4081f8434a29 to your computer and use it in GitHub Desktop.
Brute Force String Pattern matching in Ruby
This file contains 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
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