Daniel Schierbeck
12/10/2005 5:41:00 PM
StarLion wrote:
> def MakeBoard
> rcount = 0
> puts "Push enter, then begin input. (For Input Format Compliance, extra
> enter key is necessary)"
> gets
> board = [[],[],[],[],[],[],[],[],[]]
> 9.times do
> instr = gets
> board[rcount] =
> [instr[0].to_i,instr[1].to_i,instr[2].to_i,instr[3].to_i,instr[4].to_i,instr[5].to_i,instr[6].to_i,instr[7].to_i,instr[8].to_i]
> rcount += 1
> puts board[rcount]
> end #do
> return board
> end #MakeBoard
>
> Is my logic flawed here? the puts doesnt actually output anything.
I think it's because when you write `puts board[rcount]', `rcount' is 1
higher than the highest index number in board. Try this instead.
def make_board
puts "Push enter, then begin input. (For Input Format Compliance,
extra enter key is necessary)"
gets
board = [[],[],[],[],[],[],[],[],[]]
9.times do |i|
# you may want to use gets.chomp instead
instr = gets
board[i] =
[instr[0].to_i,instr[1].to_i,instr[2].to_i,instr[3].to_i,instr[4].to_i,instr[5].to_i,instr[6].to_i,instr[7].to_i,instr[8].to_i]
puts board[i] # the last item in `board'
end
return board
end
Cheers,
Daniel