Talk:Square form factorization: Difference between revisions

lang -> syntaxhighlight
(lang -> syntaxhighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 179:
 
To prove things were working as they should, I wrote a little ditty
<langsyntaxhighlight lang="Phix">integer prev = 3
sequence res = {}, r
for n=3 to 100_000 do
Line 197:
prev = p
end for
puts(1,join_by(res,3,10))</langsyntaxhighlight>
and got this, the only non-prime odd numbers that fail below 1,000,000 are indeed cubes of primes, just as advertised:
<pre>
Line 210:
: Hi Pete, thank you for bringing this up. I was just trying to be playful on making it look as close to the algorithm and pseudocode as possible, for example, the floor and sqrt routines were replaced with operators which add unnecessary layers of operation. Also many recalculation of values like √𝑁, √(𝑘*𝑁) and √Q, among others, can be avoided by using temporary variables. Above all that I didn't apply any optimization like the other entries (TBH I am too slack to understand them and fit them in :-P). Anyway, thanks again and have a nice day. --[[User:Hkdtam|Hkdtam]] ([[User talk:Hkdtam|talk]]) 17:37, 26 March 2021 (UTC)
:: No worries, if it was 20 or 100 times slower I wouldn't have said anything, but two and a half million times slower... --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 19:48, 26 March 2021 (UTC)
 
=== Strange effect of using the wrong multipliers ===
 
When translating the Wren sample, I initially made the mistake of using the subscript of the multipliers array instead of the value of the element of the array, so the start of the main loop looked like this:
<syntaxhighlight lang="algol68">
FOR multiplier FROM LWB multipliers TO UPB multipliers WHILE result = 0 DO
INTEGER d = n * multiplier;
</syntaxhighlight>
When it should have been
<syntaxhighlight lang="algol68">
FOR multiplier FROM LWB multipliers TO UPB multipliers WHILE result = 0 DO
INTEGER d = n * multipliers[ multiplier ];
</syntaxhighlight>
Doing this didn't affect the results, except a few have the Factor and Quotient round the other way, e.g., the first few results were calculated as:
<pre>
Integer Factor Quotient <-- with wrong multipliers
----------------------------------------
2501 41 61 <--
12851 71 181
13289 137 97
75301 257 293 <--
</pre>
whilst the actual results are:
<pre>
Integer Factor Quotient <-- with correct multipliers
----------------------------------------
2501 61 41 <--
12851 71 181
13289 137 97
75301 293 257 <--
</pre>
I assume this is because there are 16 multipliers, so the loop used 1, 2, 3, ..., 16 (Algol 68 arrays are 1-based by default) which includes 1, 3, 5, 7, 11, 3 * 5 - the first six proper multipliers.<br><br>
The Perl sample appears to be using the same incorrect multipliers - it shows the same factors in reverse order.<br>
--[[User:Tigerofdarkness|Tigerofdarkness]] ([[User talk:Tigerofdarkness|talk]]) 20:07, 28 September 2023 (UTC)
3,021

edits