I have a simple table that I can't quite make work. Columns are as follows
- A function returning
1ifxdivides12and0else - A function returning
1ifxdivides18and0else - Columns
1and2multiplied together to produce1ifxdivides both12and18, and0else - Column
3s individual entries multiplied by the number of1s in column3, returning4ifxdivides both12and18, and0else - 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 4s 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] 

xwhere you should havei, if you want to accumulate: E.g.Sum[4*Boole[Divisible[12, i]]*Boole[Divisible[18, i]], {i, 1, x}]$\endgroup$