Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: List processing

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37228] Re: List processing
  • From: Selwyn Hollis <selwynh at earthlink.net>
  • Date: Thu, 17 Oct 2002 00:09:14 -0400 (EDT)
  • References: <200210161825.OAA10586@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I'm not 100% sure of this, but how about

sortout[intervals_] := ({First[#1], Last[#1]} & ) /@
    Sort /@ Flatten /@ Split[Sort[intervals], #1[[2]] >= #2[[1]] & ]

?

Example:

intrvls = Table[x = Random[Integer, {0, 30}]; {x, x + 2}, {10}]

      {{18, 20}, {2, 4}, {14, 16}, {1, 3}, {0, 2}, {16, 18}, {7, 9},
        {19, 21}, {6, 8}, {6, 8}}

sortout[intrvls]

       {{0, 4}, {6, 9}, {14, 21}}

---
Selwyn Hollis



John Leary wrote:
> Greetings
> 
> This problem can be solved by conventional programming, but I wonder if 
> there is an elegant Mathematica solution ?
> 
> A list contains pairs of values, with each pair representing the lower and 
> upper edge of a sub-range.  Some of the sub-ranges partially overlap, some 
> fully overlap, others don't overlap at all.  The problem is to produce a 
> second list that contains the overall upper and lower edges of the 
> overlapping sub-ranges.
> 
> A simple example :  {{100,200},{150,250},{120,270},{300,400}}  would result 
> in {{100,270},{300,400}}.
> 
> In the real case, the input list has several hundred elements and the 
> output list typically has five elements.
> 
> I have a working solution based on loops, but there must be a more elegant 
> one.  I would be very grateful for any suggestions.
> 
> 
> Best regards
> 
> John Leary
> 
> 
> 




  • Prev by Date: Re: List processing
  • Next by Date: Re: List processing
  • Previous by thread: List processing
  • Next by thread: Re: List processing