Hi Tomaaz (and/or all),
If you have some time, could you show me this in Ruby. JB is the only Basic I have with extended integers and even that won't do SQR of arbitrary long integers. sbmeTW has found cool workaround that seems to work in JB, I wonder if it could be verified in another language, (or a better Basic would be even better!)
Here is sbmeTW code in JB that is confusing to me but seems to work 'sbmeTW Pray Pyth Tri 100.txt copied and modified 2016-01-20
print" gives prayers"
print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
'Input "input number list ";x
a=6 :b=5:c=1:s=5: D=1: z =8
for p=1 to 100
if p=2 then D=7
gosub [legs]
s=(a*b)-c
print p;") ";La;", ";Lb;", ";s;
if La*La+Lb*Lb<>s*s then
print " Error !!!"; s*s-La*La-Lb*Lb
ecount=ecount+1
else
print " Checks OK"
end if
print La*La;" + ";Lb*Lb;" ?=? ";s*s
print
c=b:b=s
next
end
[legs]
La=int(((z*b)+D)/2)
Lb=La+1
TEMPB=La+Lb
D=TEMP
TEMP=TEMPB
return
Here is my code in JB that bombs after the 20th round that I am wondering if would work in Ruby or better BASIC
'Pray Pyth Tri.txt for JB 2016-01-19 [B+MGA]
' 2016-01-19 started from copy of my post at JB,
' old business I wanted to check up on
' from copy of my post at JB,
' Have you heard of praying Pythagorean triangles?
' There is only a difference of 1 between the two legs (hence they are always primitive).
' The first is the first 3-4-5
' The secound is 20-21-29 but they are rare.
' They can be constructed from sequence that starts at 1
' Next term is INT(Last term times (SQR(2)+1)squared)
' 1, 5, 29, 169, 985,..
' Those are hypotenuse c, the legs are:
' a is INT ( SQR( (c)squared /2) )
' b is a+1
' 2016-01-19 show code of the program outlined
c=1:ecount=0:pptcount=0
while ecount<3
c= INT(c*(SQR(2)+1)^2)
a= INT( SQR((c^2)/2) )
b=a+1
pptcount=pptcount+1
print pptcount;") ";a;", ";b;", ";c
print a*a;" + ";b*b;" = ";c*c;
if a*a+b*b<>c*c then
print " Error !!!"
ecount=ecount+1
else
print " Checks OK"
end if
print
wend