Created
July 30, 2013 01:00
-
-
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
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 "* * *" | |
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