Skip to content

Instantly share code, notes, and snippets.

@serv
Created July 30, 2013 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serv/6109285 to your computer and use it in GitHub Desktop.
Save serv/6109285 to your computer and use it in GitHub Desktop.
Return order and position of the first 'x' charter-length string in 500 character-length string
puts "* * *"
puts "Enter 500 characters"
c500 = gets.chomp
puts "Would you like 4 character window or 8 character window? Type 4 or 8."
window_length = gets.chomp
result = []
window_lengthed_str = c500[0..(window_length.to_i-1)]
c500.scan(window_lengthed_str) do |c|
result << [c, $~.offset(0)[0]]
end
puts "* * *"
result.each_with_index do |r, index|
puts "Order: #{index+1}, position: #{r[1]+1}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment