- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
def get_next_line(max_level, current_level, current_line_items)
next_line_items = []
result_string = ''
if current_level == 1
next_line_items.push(1)
result_string = "1\n"
else
current_line_number = false
current_line_number_count = 0
current_index = 0
current_line_items.each do |line_number|
if current_index == 0
current_line_number = line_number
current_line_number_count = 1
else
if line_number == current_line_number
current_line_number_count = current_line_number_count + 1
else
next_line_items.push(current_line_number_count)
next_line_items.push(current_line_number)
current_line_number_count = 1
current_line_number = line_number
end
end
if current_index >= current_line_items.length - 1
next_line_items.push(current_line_number_count)
next_line_items.push(current_line_number)
end
current_index = current_index + 1
end
result_string = next_line_items.join(' ') + "\n"
end
if current_level < max_level
result_string = result_string + get_next_line(max_level, current_level + 1, next_line_items).to_s
end
# return result
result_string
end
puts 'Input max level:'
level = gets
puts ''
puts get_next_line(level.to_i, 1, [])
реальное тестовое задание кандитата.
задача - вывести несколько членов последовательности
1
11
21
1211
....