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

54 lines
1.3 KiB
Text

(pythagoreanTriples=
total prim max-peri U stack
. (.(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 Ucol
, 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
)
& !t !stack:?stack
& !loop
)
& !loop
|
)
& ( Main
= seed
. 10:?max-peri
& whl
' ( 0:?total:?prim
& (,3,4,5):?stack
& whl
' (!stack:%?seed ?stack&new-tri$!seed)
& out
$ ( str
$ ( "Up to "
!max-peri
": "
!total
" triples, "
!prim
" primitives."
)
)
& !max-peri*10:~>100000000:?max-peri
)
)
& Main$
);
pythagoreanTriples$;