Talk:Brilliant numbers

From Rosetta Code
Revision as of 13:29, 23 April 2022 by Petelomax (talk | contribs) (→‎100 limit quibble)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

100 limit quibble[edit]

In my translation of C++, I replaced for j=i to length(primes) do with for j=1 to i do. The reason being I didn't really believe the length()>100 test, whereas with 1 to i it feels (more) like that must be OK. Made no actual difference. Both might be fine. --Pete Lomax (talk) 22:23, 22 April 2022 (UTC)

Both are fine. In one case we get all products p1 x p2 where p1 <= p2, in your case it's p1 >= p2. We can stop when we have at least 100 products because at each iteration of the outer loop we increase the number of digits by 1 (if p1 and p2 both have n digits then p1 x p2 must be greater than the product of any two numbers with fewer than n digits). --Simonjsaunders (talk) 08:29, 23 April 2022 (UTC)
Oh of course, silly me, I'd kind of blanked there were three nested loops. Thanks --Pete Lomax (talk) 13:28, 23 April 2022 (UTC)