2
$\begingroup$

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$
$\endgroup$
  • 1
    $\begingroup$ Count[Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, #}], True] & /@ {10, 50, 100} evaluates to {3, 7, 10} $\endgroup$ – Bob Hanlon Jul 2 '19 at 18:39
  • 2
    $\begingroup$ 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]. $\endgroup$ – Szabolcs Jul 2 '19 at 21:00
2
$\begingroup$
Total@Boole@Table[TrueQ[FractionalPart[Sqrt[n]] == 0], {n, 1, 100, 1}]
(* 10 *)
$\endgroup$
1
$\begingroup$

If expr is one of your Tables above:

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

returns how many Trues there are.

$\endgroup$
0
$\begingroup$

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

⌊Sqrt@n⌋
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.