Use the power of data structures...
Data Structure Power
Step one
###Step one YouYou create a two different data structures consisting of pure indexes of your original matrix. On the first you create Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
Step two
###Step two CreateCreate a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
Step three
###Step three TheThe algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.
Use the power of data structures...
Data Structure Power
###Step one You create a two different data structures consisting of pure indexes of your original matrix. On the first you create Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
###Step two Create a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
###Step three The algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.
Use the power of data structures...
Data Structure Power
Step one
You create a two different data structures consisting of pure indexes of your original matrix. On the first you create Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
Step two
Create a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
Step three
The algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.
Use the power of data structures...
Data Structure Power
###Step one You create a two different data structures consisting of pure indexes of your original matrix. On the first you cratecreate Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
###Step two Create a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
###Step three The algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.
Use the power of data structures...
Data Structure Power
###Step one You create a two different data structures consisting of pure indexes of your original matrix. On the first you crate Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
###Step two Create a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
###Step three The algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.
Use the power of data structures...
Data Structure Power
###Step one You create a two different data structures consisting of pure indexes of your original matrix. On the first you create Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
###Step two Create a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
###Step three The algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.
Use the power of data structures...
Data Structure Power
###Step one You create a two different data structures consisting of pure indexes of your original matrix. On the first you crate Objects that contain "pointers" (in your case references) to the top, left, right, and bottom elements.
###Step two Create a list of indexes of the elements that are not Zero every time the matrix changes. These indexes are also references.
###Step three The algorithm will change, here is some pseudocode
for(elements in idx_of_not_zero)
{
if(1){ change_adjacent(+1);
}
In change adjacent you place the logic regarding the "if its two then don't change".
This will take more memory, but it will be faster.
Such is the tradeoff between memory and performance.