Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @matrix = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
- ## with the below code, only the first zero in the whole matrix is changed
- @matrix[0][0] = 1
- p @matrix
- ## the below code resets the matrix, but in a purely implicit way which allows the matrix's size to be set in just one variable
- @matrixsize = 10
- @blankrow = []
- until @blankrow.length == @matrixsize
- @blankrow << 0
- end
- @matrix = []
- until @matrix.length == @matrixsize
- @matrix << @blankrow
- end
- ## however, this method of resetting the matrix produces a weird result that doesn't make sense when you try to change only the first zero again
- @matrix[0][0] = 1
- p @matrix
- ## please note i tried running this code on https://repl.it which runs ruby 2.2 from 2014-12 and it produces the same result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement