Skip to content

Instantly share code, notes, and snippets.

@mosinski
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosinski/2409aa1ff1890e2f1b15 to your computer and use it in GitHub Desktop.
Save mosinski/2409aa1ff1890e2f1b15 to your computer and use it in GitHub Desktop.
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