Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created May 12, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethagnawl/07c8a15eac9bc8372f174425fc331cda to your computer and use it in GitHub Desktop.
Save ethagnawl/07c8a15eac9bc8372f174425fc331cda to your computer and use it in GitHub Desktop.
SO solution
board = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
while (input = gets.chomp.to_i) != "exit"
board = board.map.with_index do |row, i|
row.map.with_index do |column, ii|
if column == input
"x"
else
row.length * i + ii + 1
end
end
end
board.each do |outer_row|
outer_row.each { |inner_row| print "| #{inner_row} |" }
print "\n"
end
puts "Type quit for exiting game, or a number"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment