Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.2K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Select from a list of numbers out of order the ones that aren't correlative

Posted 9 years ago

I try with a list like this one

{2, 8, 9, 6, 3, 3, 9, 2, 4, 6, 10, 2, 1, 0, 3, 9, 3, 9, 7, 10}

and pretend to Select elements that are not like 8,9 or 9,8 or 3,3 I tried using as condition Abs[#1 - #2]>1 but gives a mistake slot out off range ... I suppose I need to focus the solution otherwise. Thanks for ideas

POSTED BY: Antonio AM
3 Replies

It is my pleasure!

Really good solution, I would say fast and clean !! At the moment I stay working a long and not clean solution going on subsequences of two elements and then Select[ mlist, Abs[#[[1]] - #[[2]]] > 1 &] that works but slowly Sincerely THANKS

POSTED BY: Antonio AM

As your problem is not strictly formulated, I can only suppose that the following code may be appropriate to your aim.

In[1]:= list = {2, 8, 9, 6, 3, 3, 9, 2, 4, 6, 10, 2, 1, 0, 3, 9, 3, 9,
    7, 10};

list //. {a___, b_, c_, d___} /; Abs[b - c] <= 1 -> {a, d}

Out[2]= {2, 6, 9, 2, 4, 6, 10, 0, 3, 9, 3, 9, 7, 10}
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard