How to count number of {True,True} outputs?

Do[Print[{x + y + z == 3, x + y > z}], {x, 1, 2, 1}, {y, 1, 2, 1}, {z, 1, 2, 1}]


If I run this syntax I get a series of Outputs, I am trying to Count only the number of outputs which is {True,True}

-
list = Table[{x + y + z == 3, x + y > z}, {x, 1, 2, 1}, {y, 1, 2, 1}, {z, 1, 2, 1}]; Count[list, {True, True}, Infinity]. How about using Count when you want to count? – Öskå May 2 '14 at 10:48

Just use Table instead of Do and Print, then Count with an appropriate levelspec:

Count[
Table[{x + y + z == 3, x + y > z}, {x, 2}, {y, 2}, {z, 2}],
{True, True},
{-2}
]

1

-

Here is an approach:

test = Tuples[{1, 2}, 3];
Cases[{{##1}, #1 + #2 + #3 == 3, #1 + #2 > #3} & @@@ test, {_, True,
True}]


yielding (as one would expect):{{{1, 1, 1}, True, True}}

or you could use:

Pick[test, And[#1 + #2 + #3 == 3, #1 + #2 > #3] & @@@ test]


To count just use Length (obviously unnecessary in this case)

-
FYI a nice shorthand for #1 + #2 + #3 is +## – Simon Woods May 2 '14 at 11:00
@SimonWoods thank you Simon Woods: always learning – ubpdqn May 2 '14 at 11:03
@Simon out of curiosity did you learn that from me or come up with it yourself? Do you also use 1##? – Mr.Wizard May 2 '14 at 11:05
@Mr.Wizard, I think I must have learnt it from you, sorry I should have acknowledged that. I've used 1## but only for fun. – Simon Woods May 2 '14 at 11:32
@Simon I don't expect acknowledgement; I was just curious. I'm the only one I can recall seeing use that around here but I know we have a similar style. (I love it when you show me how to make my code more terse!) – Mr.Wizard May 2 '14 at 11:50

Sometimes, storing the whole list before counting may be inappropriate (perhaps the list is huge). In this case, this solution may be useful:

count = 0;
Do[If[And @@ {x + y + z == 3, x + y > z}, count++],
{x, 1, 2, 1}, {y, 1, 2, 1}, {z, 1, 2, 1}
];
count


1

-
If the list is huge, then speed might be a consideration. And[x + y + z == 3, x + y > z] should be faster; also compiling should save time. – Michael E2 May 2 '14 at 23:38

Boole[(+##1 == 3) ~And~ (+##2 > #1)] & ~Array~ {2, 2, 2} ~Total~ -1
(* 1 *)


or

cnt = 0; (+##1 == 3)&&(+##2 > #1) & ~Array~ {2, 2, 2}//.{True :> cnt++}; cnt


or

cnt = 0; (cnt += Boole[+##1 == 3 && +##2 > #1]) & ~Array~ {2, 2, 2}; cnt

-
I edited your post to make the infix more readable, as I always recommend. Also I don't believe Rule was correct so I replaced it. +1 for syntax fun. p.s. ##1 and #1 can be written ## and #, for those who like to save characters. p.p.s. && and :> are already infix so there's not much point in writing out ~And~ or ~RuleDelayed~, other than being silly. ;-) – Mr.Wizard May 3 '14 at 2:01