summaryrefslogtreecommitdiff
path: root/miralib/ex/pyths.m
diff options
context:
space:
mode:
Diffstat (limited to 'miralib/ex/pyths.m')
-rw-r--r--miralib/ex/pyths.m9
1 files changed, 9 insertions, 0 deletions
diff --git a/miralib/ex/pyths.m b/miralib/ex/pyths.m
new file mode 100644
index 0000000..8301e47
--- /dev/null
+++ b/miralib/ex/pyths.m
@@ -0,0 +1,9 @@
+||Finds all pythagorean triangles (right triangles with integer sides)
+||Note the use of a diagonalising list comprehension, with `//' instead
+||of `|'. To see the triangles, say
+|| output
+
+output = lay (map show pyths)
+pyths = [(a, b, intsqrt (a*a+b*b)) // a <- [3..]; b<-[a+1..]; is_sq (a*a+b*b)]
+intsqrt x = entier (sqrt x)
+is_sq y = (intsqrt y) ^ 2 = y