Saturday, 31 August 2013

Ruby script hanging

Ruby script hanging

I've spent a ridiculous amount of time trying to figure out why this is
hanging. I'm assuming it has something to do with the way I've formatted
my || for the "if" statement.
rods = {
:rod1 => [3,2,1],
:rod2 => [],
:rod3 => []
}
init_rod = gets.chomp.to_sym
if ((init_rod != :rod1 || init_rod != :rod2) || init_rod != :rod3)
print "Type in \"rod1\", \"rod2\", or \"rod3\": "
elsif rods[init_rod].empty?
print "Rod has no discs. Select another rod other than #{init_rod}: "
else
disc = rods[init_rod].pop
end

No comments:

Post a Comment