Re: List processing

• To: mathgroup at smc.vnet.net
• Subject: [mg37232] Re: List processing
• From: BobHanlon at aol.com
• Date: Thu, 17 Oct 2002 00:09:37 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```In a message dated 10/16/2002 3:50:27 PM, leary at paradise.net.nz writes:

>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.
>

lst = {{100, 200}, {150, 250}, {120, 270}, {300, 400}};

List @@ Union @@ Interval /@ lst

{{100, 270}, {300, 400}}

List @@ Interval[Sequence @@ lst]

{{100, 270}, {300, 400}}

Bob Hanlon

```

• Prev by Date: Re: Plotting direction fields for a logistic equation
• Next by Date: RE: Plotting direction fields for a logistic equation
• Previous by thread: Re: List processing
• Next by thread: Re: List processing