I am not sure I quite understand the question.
"I want to find the first position where the sequence drops to zero"
From this description and looking at sequence I would select position 8 rather 7 for that location.
seq = {0,0,0,1,2,3,1,0,0,0,4,5,8,0}
I infer that you want non-zero digits followed by a zero and want the location of that zero.
Here is something that is not elegant but works
First@Select[
Flatten@Position[seq, 0] ,
# > First@Flatten@Position[seq, x_ /; x != 0] &
]
(* 8 *)
To break it down
Flatten@Position[seq, 0]
(* {1, 2, 3, 8, 9, 10, 14} *)
gives the zero positions and
Flatten@Position[seq, x_ /; x != 0]
(* {4, 5, 6, 7, 11, 12, 13} *)
gives the non-zero positions, the first of these is position 4.
I want to select from the group of zero positions the location which first exceeds the first non-zero digit (4), which is 8 for this example.
First@Select[
Flatten@Position[seq, 0] ,
# > First@Flatten@Position[seq, x_ /; x != 0] &
]
Length[First[Split[seq, #1 <= #2 || #2 != 0 &]]]. – J. M.'s missing motivation Oct 08 '16 at 17:08- As you receive help, try to give it too, by answering questions in your area of expertise.
- Take the tour and check the faqs!
- When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Oct 08 '16 at 17:26