diff --git a/pymath/__init__.py b/pymath/__init__.py index c12f1ed..5ef4f02 100644 --- a/pymath/__init__.py +++ b/pymath/__init__.py @@ -3,6 +3,7 @@ from .calculus import Expression, Polynom, Fraction, random_str, txt from .stat import Dataset, WeightedDataset +from .geometry import random_pythagore # ----------------------------- # Reglages pour 'vim' diff --git a/pymath/geometry/__init__.py b/pymath/geometry/__init__.py new file mode 100644 index 0000000..c078b0c --- /dev/null +++ b/pymath/geometry/__init__.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +# encoding: utf-8 + +from .pythagore import random_pythagore + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del diff --git a/pymath/geometry/pythagore.py b/pymath/geometry/pythagore.py new file mode 100644 index 0000000..62ceab5 --- /dev/null +++ b/pymath/geometry/pythagore.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# encoding: utf-8 + + +from random import randint + + +def random_pythagore(v_min = 1, v_max = 10, nbr_format = lambda x:x): + """ Generate a pythagore triplet + :returns: (a,b,c) such that a^2 = b^2 + c^2 + + """ + u, v = randint(v_min, v_max), randint(v_min, v_max) + while u == v: + u, v = randint(v_min, v_max), randint(v_min, v_max) + u, v = max(u,v), min(u,v) + triplet = (u**2+v**2, 2*u*v, u**2-v**2) + formated_triplet = [nbr_format(i) for i in triplet] + return formated_triplet + + + + +# ----------------------------- +# Reglages pour 'vim' +# vim:set autoindent expandtab tabstop=4 shiftwidth=4: +# cursor: 16 del