Last active
August 29, 2015 14:11
-
-
Save mosinski/2409aa1ff1890e2f1b15 to your computer and use it in GitHub Desktop.
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
puts "Podaj tekst:" | |
t = gets.chomp.split(//) | |
puts "Podaj wzorzec:" | |
p = gets.chomp.split(//) | |
n, m = t.length, p.length | |
pPos, iPos = 0, 0 | |
while iPos < n | |
if pPos == m | |
puts "Wzorzec wystepuje z przesunięciem: #{iPos - pPos}" | |
end | |
if p[pPos] == t[iPos] | |
pPos = pPos + 1; | |
iPos = iPos + 1; | |
else | |
if pPos == 0 | |
iPos = iPos + 1; | |
end | |
pPos = 0; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment