我有以下问题:
这是我想的算法:
如果对此问题有任何指导或帮助,我将非常感激。
答案 0 :(得分:2)
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'
答案 1 :(得分:1)
这是对你的问题的快速抨击。
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