I have a simple table that I can't quite make work. Columns are as follows
- A function returning
1
ifx
divides12
and0
else - A function returning
1
ifx
divides18
and0
else - Columns
1
and2
multiplied together to produce1
ifx
divides both12
and18
, and0
else - Column
3
s individual entries multiplied by the number of1
s in column3
, returning4
ifx
divides both12
and18
, and0
else - An accumulating sum of column
4
, which should therefore read{4,8,12,12,12,16,16,16,16,16}
I have problems with columns 4
and 5
. In the table below, I have had to manually enter the count for column 4
(Count
just returns 0
), and the sum doesn't work in column 5
(the sum drops back to 0
whenever column 4
equals 0
, and I have no idea how it has managed to add together four 4
s to get 24
).
How do I fix this?
TableForm[
Table[{If[MemberQ[Divisors[12], x], 1, 0],
If[MemberQ[Divisors[18], x], 1, 0],
If[MemberQ[Divisors[12], x], 1, 0]*
If[MemberQ[Divisors[18], x], 1, 0],
4*If[MemberQ[Divisors[12], x], 1, 0]*
If[MemberQ[Divisors[18], x], 1, 0],
Sum[
4*If[MemberQ[Divisors[12], x], 1, 0]*
If[MemberQ[Divisors[18], x], 1, 0], {i, 1, x}]},
{x, 1, 10}],
TableHeadings -> {{"x=1", "2", "3", "4", "5", "6", "7", "8", "9",
"10"},
{"D[12]", "D[18]", "D[12]D[18]",
"(Count[D[12]D[18]])(D[12]D[18])",
"Sum[Count[D[12]D[18]])(D[12]D[18])]"}},
TableAlignments -> Center]
x
where you should havei
, if you want to accumulate: E.g.Sum[4*Boole[Divisible[12, i]]*Boole[Divisible[18, i]], {i, 1, x}]
$\endgroup$