Skip to content

Instantly share code, notes, and snippets.

@fee1good
Last active March 20, 2017 14:37
Show Gist options
  • Save fee1good/191002973fae8b9917e10d7e6838334c to your computer and use it in GitHub Desktop.
Save fee1good/191002973fae8b9917e10d7e6838334c to your computer and use it in GitHub Desktop.
class Numbers
def initialize(str)
@str = str
@str_arr = str.split("").map(&:to_i) #создаю массив цифр из строки
end
def take_sequence
@mega_result = Array.new
@str_arr.each_index do |i|
result = Array.new
if @str_arr.length - 1 == i
return
else
if @str_arr[i] == @str_arr[i + 1] - 1
@mega_result << result.push(@str_arr[i], @str_arr[i + 1])
else
next
end
end
end
@mega_result
end
end
p Numbers.new("1235689").take_sequence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment