def insertion_sort(array)
    sorted = [array[0]]
    array.delete_at(0)
    for i in array
        sorted_index = 0
        while sorted_index < sorted.length
            if i <= sorted[sorted_index]
                sorted.insert(sorted_index,i)
                break
            elsif sorted_index == sorted.length-1
                sorted.insert(sorted_index+1,i)
                break
            end
            sorted_index+=1
            p sorted.join(" ")
        end
    end
    sorted.join(" ")
end

#input
input = "5 2 4 6 1 3"
array = input.split(" ").map{|s| s.to_i}
p insertion_sort(array)