Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Points on a line and associated intervals

by turo (Friar)
on May 17, 2006 at 21:56 UTC ( [id://550136]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Points on a line and associated intervals

i'm sleepy, but here it goes

  1. set an array of N element {distance=-1; point1; point2}
  2. for each element on your list
    1. take two adjacent elements, and calculate its distance
    2. compare the distance with the first element of the array.
      1. if the array element.distance is -1, then put your distance, and the info for your two adjacent points
      2. if you distance is lower, then, rotate the array to the right and put your elment to the first instance. Your array must be something like this [new_element, old 1, old 2,.., old n-1]
      3. if your distance is higher, try to compare with the next element of the array and start the point 2.2.

When you finish, you will have (i think) an array of 10 elemnts (at complexity O(n)), which are the ones you are searching for (supposing, of course, that your points are consecutive between them ... umm ... i'm wondering if i really grasp the problem ... i'll go to bed)

Good night

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://550136]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.