Mistři v programování na #hovnokod

Ruby #22

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, [])

Anonymous,