Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.5K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to determine Length for a number of lists?

POSTED BY: Kenneth Holland
4 Replies

I see that my reply of a few minutes ago was formatted so it was unreadable. Here it is again. Both of these work fine, the second being more compact. Thanks. After floundering around, however, I believe the easiest way to find the positions(s) of single element lists is to use: pos1=Position[ mat, { _ } ] . For double element lists (and so on) use: pos2=Position[ mat, { _ , _ }]. After you have found the position in the form { i, j } , you can recapture that element of matrix mat with Extract[ mat, pos1]. KH

POSTED BY: Kenneth Holland

Both of these work fine, the second being more compact. Thanks. After floundering around, however, I believe the easiest way to find the positions(s) of single element lists is to use pos=Position[ mat, {}]. For double element lists (and so on) use Position[mat, {,_}]. After you have found the position in the form {i,j} , you can recapture that element of matrix mat with Extract[ mat, pos]. KH

POSTED BY: Kenneth Holland
Posted 12 years ago

If the name of your matrix is mat, than this should do the job:

Map[Length, mat, {2}]
POSTED BY: Karsten 7.

Hi,

if I understand correctly this should do the trick.

First I generate a matrix which is -hopefully- of the form you want to test my algorithm:

matrix = Table[Table[RandomInteger[8] + 1, {m, 1, RandomInteger[4] + 1}], {i, 1, 9}, {j, 1, 9}]

Then this function should do the trick:

Position[ArrayReshape[Length /@ Flatten[matrix, 1], {9, 9}], 1]

Cheers, Marco

PS: You might also like http://mathworld.wolfram.com/notebooks/RecreationalMath/Sudoku.nb and http://demonstrations.wolfram.com/SudokuGame/

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard