I have two lists shown below:
list1 = {(0,0,0,0),(0,0,0,1),(0,0,1,0),...,(1,1,1,1)} list2 = {1,5,5,5,...,5}
How can I construct a function that outputs a table similar to this:
$$\begin{array}{c|c} \text{Initial vector} & \text{Period} \\ \hline (0,0,0,0) & 1 \\ (0,0,0,1) & 5 \\ (0,1,0,1) & 5 \\ (0,1,1,1) & 5 \\ \end{array}$$
I have experimented using Table, but it just outputs a list.
EDIT:
What is wrong with my function taken from one of the answers:
printPeriodTbl[vectors_, periods_] :=
Grid[Prepend[
Transpose[{Row[{"(", Row[#, ","], ")"}] & /@ vectors,
periods}], {"Initial Vector", "Period"}],
Dividers -> {2 -> True, 2 -> True}];
what I am passing into this function looks like:
vectors = {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 0, 0}, {0, 1, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 1}, {1, 0, 0, 0}, {1, 0, 0, 1}, {1, 0, 1, 0}, {1, 0, 1, 1}, {1, 1, 0, 0}, {1, 1, 0, 1}, {1, 1, 1, 0}, {1, 1, 1, 1}}
period = {1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}
Errors from this are:
Transpose::nmtx: The first two levels of {Pattern[((Row[#1,,])&)[listOfInitVectors],(Row[_,,])],listOfPeriods_} cannot be transposed. >>
Transpose::tperm: Permutation {Pattern[((Row[#1,,])&)[listOfInitVectors],(Row[_,,])],listOfPeriods_} is longer than the dimensions {2} of the expression. >>
Transpose[{list1,list2}]
then useTableForm
and add your table headers $\endgroup$list1
as{(0,0,0,0),(0,0,0,1),(0,0,1,0),...,(1,1,1,1)}
. Since you clearly know that lists are{}
the only way to interpret this is that(0,0,0,0)
must be a string. In other wordslist1
andlist 2
are both vectors (henceTranspose
). Is that actually what you mean or is it a typo? $\endgroup$