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 (2)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37237] Re: List processing (2)
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 18 Oct 2002 05:16:53 -0400 (EDT)
  • References: <aokbp7$afv$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

John,

The solution using Split that I previously supplied may unnecessarily sort
more than once -- here is a correction -- it should be slightly quicker..

lst = Table[{#, # + Random[Integer, {0, 9}]} &[
        Random[Integer, {0, 1000}]], {1000}];

FixedPoint[{Min[#],Max[#]}&/@
            Split[Sort[#], #1[[2]]\[GreaterEqual]#2[[1]]&]&,lst]//Timing

{0.22 Second,{{1,64},{66,66},{67,175},{177,363},{365,548},{551,853},{857,
      857},{858,938},{940,1003}}}

FixedPoint[{Min[#],Max[#]}&/@Split[#, #1[[2]]\[GreaterEqual]#2[[1]]&]&,
        Sort[lst]]//Timing

{0.16 Second,{{1,64},{66,66},{67,175},{177,363},{365,548},{551,853},{857,
      857},{858,938},{940,1003}}}


Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"John Leary" <leary at paradise.net.nz> wrote in message
news:aokbp7$afv$1 at smc.vnet.net...
> 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: grouping and averaging {x,y} pairs of data
  • Next by Date: RE: How to speed up this calculation?
  • Previous by thread: Re: Get rid of unwanted {}
  • Next by thread: Again, How to speed up this calculation? and more