Special pythagorean triplet: Difference between revisions

→‎{{header|Ring}}: illustrating straightforward method vs. faster method.
m (→‎{{header|REXX}}: updated output, added wording to the REXX section header.)
(→‎{{header|Ring}}: illustrating straightforward method vs. faster method.)
Line 821:
=={{header|Ring}}==
<lang ring>
see? "working..." + nl
load "stdlib.ring"
see "working..." + nl
 
? "brute force method:"
time1 = clock()
for a = 1 to 1000998
for b aa = a+1 to 1000 * a
for cb = ba + 1 to 1000999
ifbb = aa (pow(a,2)+pow( b * b,2)=pow(c,2))
c = 1000 if- a+b+c =- 1000b
if see "abb = " + a + " b = " + b + " c = " +* c + nl
? exit"a 3= " + a + " b = " + b + " c = " + c
ok exit 2
ok
next
next
next
time2 = clock()
 
? "Elapsed time = " + (time2 - time1) / 1000 + " ms"
 
? "quick method:"
 
time1 = clock()
n = 1000
n2 = n >> 1
for a = 1 to n2
b = n * (n2 - a)
if b % (n - a) = 0 exit ok
next
b /= (n - a)
? "a = " + a + " b = " + b + " c = " + (n - a - b)
time2 = clock()
 
time3 = time2/1000 - time1/1000
see? "Elapsed time = " + time3(time2 +- "time1) s"/ 1000 + nl" ms"
see "done..." + nl</lang>
</lang>
{{out}}
Quicker method is about 1000x faster.
<pre>
<pre>working...
brute force method:
a = 200 b = 375 c = 425
Elapsed time = 927.21 ms
quick method:
a = 200 b = 375 c = 425
Elapsed time = 4970.6190 sms
done...</pre>
</pre>
 
=={{header|Wren}}==