Talk:Brilliant numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
(100 limit quibble)
 
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
== 100 limit quibble ==
== 100 limit quibble ==
In my translation of C++, I replaced <code>for j=i to length(primes) do</code> with <code>for j=1 to i do</code>. 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. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 22:23, 22 April 2022 (UTC)
In my translation of C++, I replaced <code>for j=i to length(primes) do</code> with <code>for j=1 to i do</code>. 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. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|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). --[[User:Simonjsaunders|Simonjsaunders]] ([[User talk:Simonjsaunders|talk]]) 08:29, 23 April 2022 (UTC)
::Oh of course, silly me, I'd kind of blanked there were ''three'' nested loops. Thanks --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 13:28, 23 April 2022 (UTC)

Latest revision as of 13:29, 23 April 2022

100 limit quibble

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)