I have:
lightstep[m_, gg_] :=
Which[gg == {1, 1}, m = Mod[m + m, 2]]
Then I entered:
A = {{1, 1, 0}, {1, 0, 0}, {0, 0, 0}}
And I tried:
lightstep[A, {1, 1}]
And got this message:
Set::setraw: Cannot assign to raw object 1.
Set::setraw: Cannot assign to raw object 1.
Set::setraw: Cannot assign to raw object 0.
General::stop: Further output of Set::setraw will be suppressed during this calculation.
And this output:
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
Why the message?
Update: Thanks for the help everyone. I was able to complete my project.
lightstep[m_, gg_] := Module[{
m1 = {{1, 1, 0}, {1, 0, 0}, {0, 0, 0}},
m2 = {{1, 1, 1}, {0, 1, 0}, {0, 0, 0}},
m3 = {{0, 1, 1}, {0, 0, 1}, {0, 0, 0}},
m4 = {{1, 0, 0}, {1, 1, 0}, {1, 0, 0}},
m5 = {{0, 1, 0}, {1, 1, 1}, {0, 1, 0}},
m6 = {{0, 0, 1}, {0, 1, 1}, {0, 0, 1}},
m7 = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}},
m8 = {{0, 0, 0}, {0, 1, 0}, {1, 1, 1}},
m9 = {{0, 0, 0}, {0, 0, 1}, {0, 1, 1}}
},
Which[
gg == {1, 1}, Mod[m + m1, 2],
gg == {1, 2}, Mod[m + m2, 2],
gg == {1, 3}, Mod[m + m3, 2],
gg == {2, 1}, Mod[m + m4, 2],
gg == {2, 2}, Mod[m + m5, 2],
gg == {2, 3}, Mod[m + m6, 2],
gg == {3, 1}, Mod[m + m7, 2],
gg == {3, 2}, Mod[m + m8, 2],
gg == {3, 3}, Mod[m + m9, 2]
]]
Then:
DynamicModule[
{m = {{1, 1, 0}, {1, 0, 0}, {0, 0, 0}}, gg = {0, 0}},
Dynamic@(
If[gg == {0, 0}, {}, m = lightstep[m, gg]; gg = {0, 0}];
Pane[TableForm[
MapIndexed[
Button[" ", gg = #2, ImageSize -> {420/(3 + 1), 420/(3 + 1)},
Background -> {Black, RGBColor[1, .81, 0]}[[1 + #1]]] &,
m, {2}]], {450, 450}, Alignment -> Center]
)]
This was with help from (http://demonstrations.wolfram.com/LightsOutPuzzle/)[http://demonstrations.wolfram.com/LightsOutPuzzle/]
HoldFirstor friends. Take a look here: Attempting to make an assignment to the argument of a function – Kuba Nov 19 '16 at 20:49lightstep[m_, gg_] := Which[gg == {1, 1}, Return[Mod[m + m, 2]]]will add two matrices mod 2. If you want to modify your original matrix, you could then useA = lightstep[A, {1, 1}]– Chris K Nov 19 '16 at 21:34{0, 1},Mod[m + m, 2] is mathematically the zero matrix with same dimensions as m. If the 1st argument oflightshipis such a matrix, it is better writtenlightstep[m_, gg_] := Which[gg == {1, 1}, ConstantArray[0, Dimensions[m]]]– m_goldberg Nov 19 '16 at 22:10