Skip to content

Instantly share code, notes, and snippets.

@aire-con-gas
Created February 27, 2015 18:24
Show Gist options
  • Save aire-con-gas/d9f8895f8e81e28b956e to your computer and use it in GitHub Desktop.
Save aire-con-gas/d9f8895f8e81e28b956e to your computer and use it in GitHub Desktop.
Finding substring via brute force solution
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