Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {1,1,1,0,-1,-1,1,1,1,0,0,0,0,-1,-1}
- ReplaceList[{1, 1, 1, 0, -1, -1, 1, 1, 1, 0, 0, 0, 0, -1, -1},
- {___, a : PatternSequence[1, 0 .., -1], ___} :> {a}]
- (* {{1, 0, -1}, {1, 0, 0, 0, 0, -1}} *)
- ReplaceList[{1, 1, 1, 0, -1, -1, 1, 1, 1, 0, 0, 0, 0, -1, -1},
- {s___, a : PatternSequence[1, 0 .., -1], ___} :>
- With[{l = Length[{s}]}, {{l + 1, l + Length[{a}]}, {a}}]]
- (* {{{3, 5}, {1, 0, -1}}, {{9, 14}, {1, 0, 0, 0, 0, -1}}} *)
- getSeq3[list_] :=
- Module[{z = Split[Select[Pick[Range@Length@list, list, 0],
- 1 < # < Length@list &], #2 == #1 + 1 &][[All, {1, -1}]]},
- {# + {-1, 1}, list[[#[[1]] - 1 ;; #[[2]] + 1]]} & /@
- Select[z, (list[[#[[1]] - 1]] == 1 && list[[#[[2]] + 1]] == -1) &]]
- getSeqSP[list_] :=
- Module[{sp = StringPosition[FromCharacterCode[list + 2],
- FromCharacterCode[3] ~~ Repeated[FromCharacterCode[2], {1, Infinity}] ~~
- FromCharacterCode[1]]},
- Transpose[{sp, Rest@Extract[list, Prepend[Transpose[{Span @@@ sp}], {{}}]]}]]
Add Comment
Please, Sign In to add comment