-
-
Save anonymous/38748b1c6831dad868be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment