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"'

In reply to Re: Points on a line and associated intervals by turo
in thread Points on a line and associated intervals by srdst13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.