I have been working on what seems to be a simple task that is driving me nuts. So if you fancy a programming challenge ... read on.
I want to be able to take a number range e.g. [1:20] and print the values using a mechanism similar to a binary serach algorithm. So, print first the lowest value (in this case 1) and then the mid value (e.g. in this case 10) and then divide the range into quarters and print the values at 1/4 and 3/4 (in this case, 5 and 15) and then divide into eights and so on until all values in the range have been printed.
The application of this (which isn't really necessary to understand here) is for a memory page access mechanism that behaves more efficiently when pages are accessed at the mid ranges first.
For this problem, it would be sufficient to take any number range and print the values in the manner described above.
Any thoughts on this? A psuedo code solution would be fine. I would show an attempt to this but everything I've tried so far doesn't cut it. Thanks.
Update: As requested, the desired output for the example [1:20] would be something like this: 1, 10, 5, 15, 3, 7, 12, 17, 2, 4, 6, 8, 11, 13, 16, 18, 9, 19, 20
This output could be presented in many similar ways depending on the algorithm used. But, the idea is to display first the half values, then the quarters, then the eights, then 16ths, etc leaving out previously presented values.