4
$\begingroup$

I want to visualize how Flatten works and have a slider that changes the level of flattening.

Here is the list of lists I'm using and Flatten function.

bifurcate[list_] := Nest[Partition[#, 2] &, list, Floor[Log[2, Length[list1]]]]

(structured = bifurcate[list1])//TreeForm

structured // Flatten[#, n] &

I want to be able to change the value of n from 1 to 3 with a step of 1,

However,

TreeForm[Flatten[structured, n]], {n, 0, 3}

doesn't work. What am I doing wrong?

$\endgroup$
1
  • $\begingroup$ Shouldn't bifurcate use Length[list] rather than Length[list1]? $\endgroup$ Feb 22, 2019 at 21:04

1 Answer 1

6
$\begingroup$

I think first clean up structured. Then

Manipulate[TreeForm[Flatten[structured, n]], {n, Range[0,3]}]

will give the TreeForm for n in {0,1,2,3}. Just Range[3] for n in {1,2,3}. This is not a "slider" but discrete choices since n is an integer.

$\endgroup$
1
  • 4
    $\begingroup$ For a slider, just use {n, 0, 3, 1} instead of {n, Range[0,3]}. $\endgroup$ Feb 22, 2019 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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