Skip to content

Instantly share code, notes, and snippets.

@sofakingworld
Last active March 13, 2017 13:30
Show Gist options
  • Save sofakingworld/92e0b19f52125072a502f82425638edb to your computer and use it in GitHub Desktop.
Save sofakingworld/92e0b19f52125072a502f82425638edb to your computer and use it in GitHub Desktop.
# test for Flatstack
# https://github.com/fs/test-tasks/tree/master/ruby
# Дана последовательность:
# 1
# 11
# 21
# 1211
# 111221
# 312211
# Нужно чтобы ваша программа могла продолжить данную последовательность. Можете в реализации использовать любые библиотеки.
def seq(count)
start_value = '1'
(count-1).times do
start_value.gsub!(/(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)/) do |m|
m = m.length.to_s+m[0]
end
end
start_value
end
seq(10) # => "13211311123113112211"
seq(4) # => "1211"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment