Finding items satisfying a condition in a list using patterns

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Why the following command



Cases[1, 2, 6, 3, 4, 8, 5, x_, y_, z_ /; (y > Max[x, z]):>y]


doesn't return the y values that are greater than their neighbors in the list?
I am expecting to have an output like 6,8.










share|improve this question









New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • For this question, I want to know how can I do it using patterns and I am not looking for alternative solutions.
    – The Legend of 1991
    2 hours ago














up vote
1
down vote

favorite












Why the following command



Cases[1, 2, 6, 3, 4, 8, 5, x_, y_, z_ /; (y > Max[x, z]):>y]


doesn't return the y values that are greater than their neighbors in the list?
I am expecting to have an output like 6,8.










share|improve this question









New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • For this question, I want to know how can I do it using patterns and I am not looking for alternative solutions.
    – The Legend of 1991
    2 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Why the following command



Cases[1, 2, 6, 3, 4, 8, 5, x_, y_, z_ /; (y > Max[x, z]):>y]


doesn't return the y values that are greater than their neighbors in the list?
I am expecting to have an output like 6,8.










share|improve this question









New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Why the following command



Cases[1, 2, 6, 3, 4, 8, 5, x_, y_, z_ /; (y > Max[x, z]):>y]


doesn't return the y values that are greater than their neighbors in the list?
I am expecting to have an output like 6,8.







pattern-matching cases






share|improve this question









New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago









Henrik Schumacher

40.2k255120




40.2k255120






New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









The Legend of 1991

202




202




New contributor




The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






The Legend of 1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • For this question, I want to know how can I do it using patterns and I am not looking for alternative solutions.
    – The Legend of 1991
    2 hours ago
















  • For this question, I want to know how can I do it using patterns and I am not looking for alternative solutions.
    – The Legend of 1991
    2 hours ago















For this question, I want to know how can I do it using patterns and I am not looking for alternative solutions.
– The Legend of 1991
2 hours ago




For this question, I want to know how can I do it using patterns and I am not looking for alternative solutions.
– The Legend of 1991
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










There are no Lists of length 3 in the input at level 1. So Cases cannot find anything. However SequenceCases can because it interprets lists as sequences.



SequenceCases[
1, 2, 6, 3, 4, 8, 5,
x_, y_, z_ /; (y > Max[x, z]) :> y,
Overlaps -> True
]



6, 8







share|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    The Legend of 1991 is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182901%2ffinding-items-satisfying-a-condition-in-a-list-using-patterns%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    There are no Lists of length 3 in the input at level 1. So Cases cannot find anything. However SequenceCases can because it interprets lists as sequences.



    SequenceCases[
    1, 2, 6, 3, 4, 8, 5,
    x_, y_, z_ /; (y > Max[x, z]) :> y,
    Overlaps -> True
    ]



    6, 8







    share|improve this answer
























      up vote
      3
      down vote



      accepted










      There are no Lists of length 3 in the input at level 1. So Cases cannot find anything. However SequenceCases can because it interprets lists as sequences.



      SequenceCases[
      1, 2, 6, 3, 4, 8, 5,
      x_, y_, z_ /; (y > Max[x, z]) :> y,
      Overlaps -> True
      ]



      6, 8







      share|improve this answer






















        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        There are no Lists of length 3 in the input at level 1. So Cases cannot find anything. However SequenceCases can because it interprets lists as sequences.



        SequenceCases[
        1, 2, 6, 3, 4, 8, 5,
        x_, y_, z_ /; (y > Max[x, z]) :> y,
        Overlaps -> True
        ]



        6, 8







        share|improve this answer












        There are no Lists of length 3 in the input at level 1. So Cases cannot find anything. However SequenceCases can because it interprets lists as sequences.



        SequenceCases[
        1, 2, 6, 3, 4, 8, 5,
        x_, y_, z_ /; (y > Max[x, z]) :> y,
        Overlaps -> True
        ]



        6, 8








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Henrik Schumacher

        40.2k255120




        40.2k255120




















            The Legend of 1991 is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            The Legend of 1991 is a new contributor. Be nice, and check out our Code of Conduct.












            The Legend of 1991 is a new contributor. Be nice, and check out our Code of Conduct.











            The Legend of 1991 is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182901%2ffinding-items-satisfying-a-condition-in-a-list-using-patterns%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke