0
$\begingroup$

Suppose we have a list of integers for arbitrary $n\in\mathbb{N}$

Range[1,n]

We take the integer in the list that rounds closest to $x=1$, $x=n$, and $x=1+(n-1)/2$.

Next we take the integers that round closest to $x=1+(n-1)/4$, $x=1+3(n-1)/4$ without taking the elements from the previous sub-list.

Then we take integers that round closest to $x=1+(n-1)/8$, $x=1+3(n-1)/8$, $x=1+5(n-1)/8$, $x=1+7(n-1)/8$ without taking the elements from the previous two sub-lists.

We continue taking the integers that round closest to $x=1+(n-1)/2^r$, $x=1+3(n-1)/2^r$,…,$x=1+(2^r-1)(n-1)/2^r$ until we reach an $r\in\mathbb{N}$ where there are no more elements that aren’t in the previous sub-lists.

What would a list of all the sub-lists look like.

For instance, if we have

Range[1,6]

How would we create a function that takes a list of all the sub-lists of this list?

$\endgroup$

1 Answer 1

2
$\begingroup$

Note: in MMA "Round" rounds to the nearest even integer. The following uses this definition.

We first create a function "get" that returns: "x=1+(n−1)/2r , x=1+3(n−1)/2r,…,x=1+(2r−1)(n−1)/2r". Then we create the first sublist, because it is special. Next we iterate until the original list is exhausted:

n = 6; (*length of original list*)
d = Range[1, n];

get[m_, n_] := Module[{},
  Round[1 + (n - 1) Table[2 i - 1, {i, 1, 2^m/2}] / 2^m]
  ]

t = {1, get[1, n][[1]], n};
res = {t};
d = Select[d, ! MemberQ[t, #] &];

sel[m_, d_, n_] := Module[{t},
   t = get[m, n];
   {Select[d, MemberQ[t, #] &], Select[d, ! MemberQ[t, #] &]}
   ];

i = 2; While[d != {}, If[i > 5, Break[]]; {t, d} = sel[i++, d, n]; 
 Print[{d, t}]; AppendTo[res, t]]
res

(* {{1, 4, 6}, {2, 5}, {3}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.