Here's my (primitive) work out in J
of generating primitive Pythagorean triples (ppt) based on
http://mathworld.wolfram.com/PythagoreanTriple.html

Generator matrices

   U=: 1 2 2 , _2 _1 _2 ,: 2 2 3
   A=: 1 2 2 , 2 1 2 ,: 2 2 3
   D=: _1 _2 _2 , 2 1 2 ,: 2 2 3

Starting ppt
   mada=: 3 4 5

Limiting expression for selecting primitives,
in this case only ppt's with hypotenuse < 100

   flim =: 100 >  {:

   dot =: +/ . *

   gppt =: 3 : 0
M =. y
r =. ,: mada
ppt =. mada dot M
while. flim ppt do.
  r=. r , ppt
  ppt =. {: r dot M
end.
}. r
)

Array of ppts:
   ppts=: mada, (gppt U) , (gppt D), (gppt A)


No doubt there's a more J-ish way in doing this,
especially for gppt ??!!

greetings,

@@i=arie

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to