Created
February 27, 2015 18:24
-
-
Save aire-con-gas/d9f8895f8e81e28b956e to your computer and use it in GitHub Desktop.
Finding substring via brute force solution
This file contains hidden or 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
def in_str(needle, haystack) | |
for i in (0..haystack.chars.length - 1) | |
if needle.chars[0] == haystack.chars[i] | |
found = true | |
for j in (0..needle.chars.length - 1) | |
if needle[j] != haystack[i + j] | |
found = false | |
break | |
end | |
end | |
if found | |
puts "Found needle #{needle} in #{haystack} at position #{i}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment