I know this is a novice question but I would like a pattern for a list containing zero or more zeros followed by exactly one 1, followed by zero or more zeros. Something like: {0___,1,0___}
But specifying that 0 must be zero.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI believe you're looking for RepeatedNull
Count[IdentityMatrix[10], {0 ..., 1, 0 ...}]
(* 10 *)
..
and...
that isRepeated
andRepeatedNull
rather thanBlank
and its friends. $\endgroup$1
and1.
or0
and0.
. Generally, you can also use/;
and specify an arbitrary condition in patterns, e.g.row_ /; Count[row, 1] == 1 && Union[row] == {0, 1}
(not necessarily the best solution for this particular problem). $\endgroup$