Skip to main content
added 477 characters in body
Source Link
E. Chan-López
  • 31.1k
  • 3
  • 29
  • 50
listl = {1, 4, 3, 2, 5};

Using ReplaceList:

ReplaceList[Split[lista(*Find elements greater than the one before*)

ReplaceList[Split[l, Less], {___, s : {a_, b__} /; a < b, ___} :> Last@s]

(*{4, 5}*)

(*Find elements smaller than the next one*)

ReplaceList[Split[l, Less], {___, s : {a_, b__} /; a < b, ___} :> First@s]

(*{1, 2}*)

(*Find a valley*)

ReplaceList[Split[l, Greater], {___, s : {a_, b_, c_} /; a > b, ___} :> Last@s]

(*{2}*)

(*Find a peak*)

ReplaceList[Split[l, Greater], {___, s : {a_, b_, c_} /; a > b, ___} :> First@s]

(*{4}*)

{4, 5}

list = {1, 4, 3, 2, 5};

Using ReplaceList:

ReplaceList[Split[lista, Less], {___, s : {a_, b__} /; a < b, ___} :> Last@s]

{4, 5}

l = {1, 4, 3, 2, 5};

Using ReplaceList:

(*Find elements greater than the one before*)

ReplaceList[Split[l, Less], {___, s : {a_, b__} /; a < b, ___} :> Last@s]

(*{4, 5}*)

(*Find elements smaller than the next one*)

ReplaceList[Split[l, Less], {___, s : {a_, b__} /; a < b, ___} :> First@s]

(*{1, 2}*)

(*Find a valley*)

ReplaceList[Split[l, Greater], {___, s : {a_, b_, c_} /; a > b, ___} :> Last@s]

(*{2}*)

(*Find a peak*)

ReplaceList[Split[l, Greater], {___, s : {a_, b_, c_} /; a > b, ___} :> First@s]

(*{4}*)
Source Link
E. Chan-López
  • 31.1k
  • 3
  • 29
  • 50

list = {1, 4, 3, 2, 5};

Using ReplaceList:

ReplaceList[Split[lista, Less], {___, s : {a_, b__} /; a < b, ___} :> Last@s]

{4, 5}