在数组中添加元素

|                                                                                                                       
已邀请:
        
loop do
  x = Array.new(6){rand(99)}
  y = []
  x.each{|k| y.push(k + y.last.to_i)}
  y.shift
  break if y.include?(gets.to_i)
end
puts \'message\'
    
        这是您遇到问题的捷径。
def check_number_in_array
  x = Array.new(6)
  y = []
  begin
    x.collect! { rand(99) }
    y.clear
    sum = 0
    x.each do |i|
      sum = sum+i
      y << sum
    end
    gets
    # The following lines are just for \"debugging\"
    print \"x = [ \"
    x.each {|i| print i, \" \"}
    print \"]\\ny = [ \"
    y.each {|i| print i, \" \"}
    print \"]\\n\"
  end while !y.include?($_.to_i)
  puts \"Good guess!\"
end
    

要回复问题请先登录注册