Guest User

Untitled

a guest
Jul 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. {1,1,1,0,-1,-1,1,1,1,0,0,0,0,-1,-1}
  2.  
  3. ReplaceList[{1, 1, 1, 0, -1, -1, 1, 1, 1, 0, 0, 0, 0, -1, -1},
  4. {___, a : PatternSequence[1, 0 .., -1], ___} :> {a}]
  5.  
  6. (* {{1, 0, -1}, {1, 0, 0, 0, 0, -1}} *)
  7.  
  8. ReplaceList[{1, 1, 1, 0, -1, -1, 1, 1, 1, 0, 0, 0, 0, -1, -1},
  9. {s___, a : PatternSequence[1, 0 .., -1], ___} :>
  10. With[{l = Length[{s}]}, {{l + 1, l + Length[{a}]}, {a}}]]
  11.  
  12. (* {{{3, 5}, {1, 0, -1}}, {{9, 14}, {1, 0, 0, 0, 0, -1}}} *)
  13.  
  14. getSeq3[list_] :=
  15. Module[{z = Split[Select[Pick[Range@Length@list, list, 0],
  16. 1 < # < Length@list &], #2 == #1 + 1 &][[All, {1, -1}]]},
  17.  
  18. {# + {-1, 1}, list[[#[[1]] - 1 ;; #[[2]] + 1]]} & /@
  19. Select[z, (list[[#[[1]] - 1]] == 1 && list[[#[[2]] + 1]] == -1) &]]
  20.  
  21. getSeqSP[list_] :=
  22. Module[{sp = StringPosition[FromCharacterCode[list + 2],
  23. FromCharacterCode[3] ~~ Repeated[FromCharacterCode[2], {1, Infinity}] ~~
  24. FromCharacterCode[1]]},
  25.  
  26. Transpose[{sp, Rest@Extract[list, Prepend[Transpose[{Span @@@ sp}], {{}}]]}]]
Add Comment
Please, Sign In to add comment