# How do I loop my "If" statement?

I have list given by:

  d=
{{{1,2},{1,1},{2,3}},
{{1,4},{3,3},{2,1}},
{{1,1},{3,1},{3,3}}}


Each row in the list is a different generation of the list. I'm trying to figure out how to look at each iteration and see if any of the elements in each sublist are the same number, e.g. in generation "1" the middle sublist would fit this criteria since it's {1,1}. I have an If statement that finds out this information for a singular row:

m = 1;
tt=Table[
If[
d[[m, l]][[1]] == d[[m, l]][[2]],
Print["Same"],
Print["Different"]],
{l, 1, Length[d[[1]]]}];


I would like to loop the "If" statement above so that it looks at all generations not just generation 1 in list "d." I then want to go through each table given by "tt" and find the number of times "Same" is printed, for each separate generation. Using Length[tt] doesn't distinguish between the two printed words so I'm not sure what control I need to add to have the number of only same printed. I've tried to use a For loop on the If statement to get it to perform the desired function but I know it's best to avoid usage of that. Any help would be appreciated.

• This will count the number of pairs that are dupes: Count[#, v_?VectorQ /; Signature[v] == 0] & /@ {{{1, 2}, {1, 1}, {2, 3}}, {{1, 4}, {3, 3}, {2, 1}}, {{1, 1}, {3, 1}, {3, 3}}} Is this something you want? Commented Apr 21, 2020 at 1:00
• Pretty cool use of Signature to check whether all the elements are the same! Commented Apr 21, 2020 at 1:03
• Yes that is what I'm looking for. Would it be possible to do the same thing for triplets? Commented Apr 21, 2020 at 1:16
• Did you try it out already on triplets? It should work there, too. (OTOH, Signature[] will catch something like {1, 1, 2}, which might be what you don't want.) Commented Apr 21, 2020 at 1:21

You can count the number of tuples composed out of identical integers for each sublist with this expression:

Map[Count[#, {n_Integer ..}] &, d]


which yields for your example of d above

{1, 1, 2}

• +1 but a little room for improvement, IMHO Commented May 23, 2020 at 20:11
d = {{{1, 2}, {1, 1}, {2, 3}}, {{1, 4}, {3, 3}, {2, 1}}, {{1, 1}, {3, 1}, {3, 3}}};

Count[{a_ ..}] /@ d

{1, 1, 2}