I use the Table
code from your second code block and strip out the Graphics
directives since I think that ArrayPlot
is actually the most efficient way to plot this.
mytable = Table[
Table[
If[EvenQ[Binomial[col, k]], 1, 0], {col, 0, n, 1}, {k, 0, col,
1}], {n, {7, 15, 31, 63, 127, 255}}];
This is going to result in $mytable$ having 6 different ragged matrices (that is the first row will only have a single number, the second row 2 numbers, etc.). We can easily plot them with:
ArrayPlot /@ PadLeft /@ mytable
The /@
notation basically means "iterate over all of the parts of whatever comes after" and is sometimes a nice substitute for Table
. So PadLeft/@mytable
is going to create rectangular matrices by padding the left side of each row with zeros, then we iterate over all of those padded matrices with ArrayPlot. This gets us:
Which doesn't have the exact same colouring as yours, but it acts as a quick check to make sure they look the same. If you decided you wanted to use ArrayPlot
yourself, there are options for colouring it however you like.
tally = Tally /@ Flatten /@ mytable
fractions = N @ #[[2, 2]]/Total[#[[All, 2]]] & /@ tally
Now I use the Tally
function on the original unpadded list. I have to Flatten
it first since I want to see how many 0s and 1s there are, I don't want it to tell me how many of each list of 0s and 1s there are. You can try Tally /@ mytable
to see the difference. The N
in the second line tells it to return decimal numbers (0.25) rather than exact numbers (1/4). The number sign is a Slot
which is basically just a placeholder. I'm dividing the second-row second-column value of each list that I put into $tally$. The first list in $tally$ looks like: {{0, 27}, {1, 9}}
telling us there are 27 zeroes and 9 ones. So all the second row does is go 9/(9+27) to get us 1/4.
You can now easily combine this with the list of n values:
{{7, 15, 31, 63, 127, 255}, fractions*100}\[Transpose]//TableForm
I have to multiply the fractions by 100 to get percentages, and the \[Transpose]
is there to put them into nice columns. The //TableForm
takes the whole thing and turns it into a nice table.
Polygon
? $\endgroup$