in reply to array splitting

  1. Customarily, posting some code will get better help than a simple question
  2. Your definition of "neighbor" appears (from the sample) to mean "the next-adjacent number -- after each test/remove/keep action." But this is NOT unambiguous, from your sample data.
    Consider: (5,6,7,8,9,10, 15, 20...)
    A tighter definition may actually reveal the answer you seek, as at least my reading of your sample makes me believe their can be cases where your final requirement cannot be satisfied for certain data.

HTH

Replies are listed 'Best First'.
Re^2: array splitting
by CColin (Scribe) on Jun 05, 2007 at 11:49 UTC
    >(5,6,7,8,9,10, 15, 20...)
    That can't happen - See the condition above in that no neighbour (ie. next adjacent number) is ever less than 5, and also all sequences are always ascending. Hence there should be a solution for this type of final data. Here is some code that sorts the first list so that all distances between numbers in the first list 10 or more, but fails for the second list when 2 or more consecutive numbers are less than 10.
    $count = 0; $time = 0; $last_time = 0; $time_diff = 100; #to ensure the first value appears in list 1 foreach $time (@times) { unless ($count == 0) {$time_diff = $last_time - $time}; if ($time_diff >= 10) {push (@times1, $time} else {push (@times2, $time)}; $last_time = $time; $count ++; } #end foreach
Re^2: array splitting
by girarde (Hermit) on Jun 05, 2007 at 15:53 UTC
    Unless more alternative arrays can be added, which may not be the case.