I have a minor problem to solve.
Due to a problem where my Dad works, he needs to figure out how to sort some numbers.
But they need to be sorted such that there is more than 2 between each number in the sequence.
eg. 2, 4, 6, 8 would become 4, 8, 2, 6.
The problem is in figuring out the 'best' sort algorithm to do this programatically.
Oh and ideally using every frequency.
(The background is that the numbers represent 'channel numbers' on a radio system, and they're separated by 50Mhz. If they're less than 2 apart, then there's interference)
There's probably a beer (or other drink of choice) in it for anyone who can give me a good solution.
Due to a problem where my Dad works, he needs to figure out how to sort some numbers.
But they need to be sorted such that there is more than 2 between each number in the sequence.
eg. 2, 4, 6, 8 would become 4, 8, 2, 6.
The problem is in figuring out the 'best' sort algorithm to do this programatically.
Oh and ideally using every frequency.
(The background is that the numbers represent 'channel numbers' on a radio system, and they're separated by 50Mhz. If they're less than 2 apart, then there's interference)
There's probably a beer (or other drink of choice) in it for anyone who can give me a good solution.
no subject
Date: 2004-04-02 04:09 am (UTC)no subject
Date: 2004-04-02 04:36 am (UTC)More than 2. (I've modified the post a little to clarify)
no subject
Date: 2004-04-02 09:32 am (UTC)no subject
Date: 2004-04-02 09:50 am (UTC)First, sort the list in ascending order, standard problem. Hack the list into two equal lists, a one of big numbers and a one of small numbers. Keep them sorted. Then just read alternate numbers off the two lists.
That'll run into problems if the number spread isn't sufficently broad, but if that's the case then you're probably screwed anyway.
And an example.
7,3,6,5,9,1,8,2,10,4 => 1,2,3,4,5,6,7,8,9,10 => 1,2,3,4,5 | 6,7,8,9,10
=> 1,6, 2,7, 3,8, 4,9, 5,10
And one where it fails
1,2,3,6 => 1,2 | 3,6 => 1,3,2,6
Now, find yourself a mathematician to prove that it works.
Tristan
no subject
Date: 2004-04-02 10:06 am (UTC)