Steady squares: Difference between revisions
Content added Content deleted
(Added PL/0) |
|||
Line 1,463: | Line 1,463: | ||
</pre> |
</pre> |
||
Which is a whopping 35-fold speedup, so obviously ''all'' I need to do is make the compiler emit similarly efficient code... |
Which is a whopping 35-fold speedup, so obviously ''all'' I need to do is make the compiler emit similarly efficient code... |
||
=={{header|PL/0}}== |
|||
<syntaxhighlight lang="pascal"> |
|||
const maxnumber = 10000; |
|||
var p10, n, d, nd, n2; |
|||
begin |
|||
p10 := 10; |
|||
n := 0; |
|||
while n <= maxnumber do begin |
|||
if n = p10 then p10 := p10 * 10; |
|||
d := 0; |
|||
while d < 6 do begin |
|||
if d = 5 then d := 6; |
|||
if d = 1 then d := 5; |
|||
if d = 0 then d := 1; |
|||
nd := n + d; |
|||
n2 := nd * nd; |
|||
n2 := n2 - ( ( n2 / p10 ) * p10 ); |
|||
if n2 = nd then ! nd |
|||
end; |
|||
n := n + 10 |
|||
end |
|||
end. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 |
|||
5 |
|||
6 |
|||
25 |
|||
76 |
|||
376 |
|||
625 |
|||
9376 |
|||
</pre> |
|||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
Line 1,657: | Line 1,692: | ||
9376**2: 87909376 |
9376**2: 87909376 |
||
</pre> |
</pre> |
||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
works with swi-prolog |
works with swi-prolog |