In my code I have
With[
{
rowCells=(genCells[#]&/@genSpecs[#])&/@clueRows,
colCells=(genCells[#]&/@genSpecs[#])&/@clueCols
},
While[Not@isDone@Flatten@constraintTable,
constraintTable=(Thread[f[rowCells,constraintTable]]/.f-> constraintStrip);
constraintTable=(Thread[f[colCells,constraintTable\[Transpose]]]
/.f-> constraintStrip)\[Transpose];
]
]
but when I attempt to replace the substitutions for f with
With[
{
rowCells=(genCells[#]&/@genSpecs[#])&/@clueRows,
colCells=(genCells[#]&/@genSpecs[#])&/@clueCols
},
While[Not@isDone@Flatten@constraintTable,
constraintTable=(Thread[constraintStrip[rowCells,constraintTable]]);
constraintTable=(Thread[constraintStrip[colCells,constraintTable\[Transpose]]]
/.f-> constraintStrip)\[Transpose];
]
]
I get
Transpose::nmtx: The first two levels of {Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0],Transpose[0]} cannot be transposed. >>
Transpose::nmtx: "The first two levels of {Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[],Transpose[]} cannot be transposed. \!\(\*ButtonBox[\">>\",
Why do I need to substitute in this way? How can avoid having to do so?
I have a similar issue with
showTable[t_]:=
Grid[
Join[
Join[
ConstantArray["",{9,9},(Style[#,Bold]&/@PadLeft[#,9,""]&/@clueCols)]\[Transpose],
(Thread[f[(Style[#,Bold]&/@PadLeft[#,9,""]&/@clueRows),
(t/.cellGraphics)
]
]/.f->Join)
],
gridSpecs
];
where a substitution is also required in Thread to avoid errors.
Answer
If you want to avoid the substitution, it might be more "elegant" to use MapThread:
MapThread[Join, {colCells, constraintTable\[Transpose]}]
This works like Thread, but Join directly operates on the right arguments.
Comments
Post a Comment