D
Drew Olson
Hello all -
I'm getting quite frustrated with a very "easy" part of this
problem...reading the input! Basically, the input is given as so:
1
1 2
1 3 2
1 4 2 1
What I intend to do is read the input line by line, split the lines by
spaces and store each substring as the associated integer. Essentially I
want to end up with a two dimensional array holding the integers shown
above. I'm using the following line of code:
a = readlines.each{|i|i.split(" ").each{|j|j=j.to_i}}
However, when I do a puts I see the following:
puts a[1][1] => 32
GAH! Why is it printing the ascii character value? Do I have a logic
flaw in the way I'm reading the input? Is there a better way to read the
input? Should I just tear my hair out?
Thanks,
Drew
I'm getting quite frustrated with a very "easy" part of this
problem...reading the input! Basically, the input is given as so:
1
1 2
1 3 2
1 4 2 1
What I intend to do is read the input line by line, split the lines by
spaces and store each substring as the associated integer. Essentially I
want to end up with a two dimensional array holding the integers shown
above. I'm using the following line of code:
a = readlines.each{|i|i.split(" ").each{|j|j=j.to_i}}
However, when I do a puts I see the following:
puts a[1][1] => 32
GAH! Why is it printing the ascii character value? Do I have a logic
flaw in the way I'm reading the input? Is there a better way to read the
input? Should I just tear my hair out?
Thanks,
Drew