RosettaCodeData/Task/Pythagorean-triples/Bracmat/pythagorean-triples-1.bracmat
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

53 lines
1.2 KiB
Text

(pythagoreanTriples=
total prim max-peri U
. (.(1,-2,2) (2,-1,2) (2,-2,3))
(.(1,2,2) (2,1,2) (2,2,3))
(.(-1,2,2) (-2,1,2) (-2,2,3))
: ?U
& ( new-tri
= i t p Urows Urow Ucols
, a b c loop A B C
. !arg:(,?a,?b,?c)
& !a+!b+!c:~>!max-peri:?p
& 1+!prim:?prim
& div$(!max-peri.!p)+!total:?total
& !U:?Urows
& ( loop
= !Urows:(.?Urow) ?Urows
& !Urow:?Ucols
& :?t
& whl
' ( !Ucols:(?A,?B,?C) ?Ucols
& (!t,!a*!A+!b*!B+!c*!C):?t
)
& new-tri$!t
& !loop
)
& !loop
|
)
& ( Main
= seed
. (,3,4,5):?seed
& 10:?max-peri
& whl
' ( 0:?total:?prim
& new-tri$!seed
& out
$ ( str
$ ( "Up to "
!max-peri
": "
!total
" triples, "
!prim
" primitives."
)
)
& !max-peri*10:~>10000000:?max-peri
)
)
& Main$
);
pythagoreanTriples$;