# Find the number of true's in a TrueQ expression

How can I find how many times the code:

Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, 1, m, 1}]


Gives the value True back for a variable $$m$$?

So, we know that for example:

• Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, 1, 10, 1}] must give $$3$$
• Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, 1, 50, 1}] must give $$7$$
• Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, 1, 100, 1}] must give $$10$$
• Count[Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, #}], True] & /@ {10, 50, 100} evaluates to {3, 7, 10} – Bob Hanlon Jul 2 '19 at 18:39
• Why are you using TrueQ here? It seems like a misuse that might get you in trouble if you do not fully understand what TrueQ does. Try e.g. TrueQ[x==0]. – Szabolcs Jul 2 '19 at 21:00

## 3 Answers

Total@Boole@Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, 1, 100, 1}]
(* 10 *)


If expr is one of your Tables above:

Select[expr, # == True &] // Length


returns how many Trues there are.

For any integer n you can get the desired number using simply

⌊Sqrt@n⌋