Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
1  
I think what you want is .. and ... that is Repeated and RepeatedNull rather than Blank and its friends. –  Carlo Aug 8 at 15:19
    
Yes, thanks to Carlo and Micahal E2. I am using this to build a row reduction method without loops. –  John McGee Aug 8 at 16:30
    
When using patterns, beware of the difference between 1 and 1. or 0 and 0.. 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). –  Szabolcs Aug 8 at 17:39

1 Answer 1

up vote 4 down vote accepted

I believe you're looking for RepeatedNull

Count[IdentityMatrix[10], {0 ..., 1, 0 ...}]
(* 10 *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.