2016-01-23 19:20:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
|
|
|
|
from random import randint
|
|
|
|
|
|
|
|
|
2019-10-13 19:01:31 +00:00
|
|
|
def random_pythagore(v_min=1, v_max=10, nbr_format=lambda x: x):
|
2016-01-23 19:20:12 +00:00
|
|
|
""" 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)
|
2017-04-16 08:27:06 +00:00
|
|
|
u, v = max(u, v), min(u, v)
|
2019-10-13 19:01:31 +00:00
|
|
|
triplet = (u ** 2 + v ** 2, 2 * u * v, u ** 2 - v ** 2)
|
2016-01-23 19:20:12 +00:00
|
|
|
formated_triplet = [nbr_format(i) for i in triplet]
|
|
|
|
return formated_triplet
|
|
|
|
|
2019-10-13 19:01:31 +00:00
|
|
|
|
2016-01-23 19:20:12 +00:00
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
2017-04-16 08:27:06 +00:00
|
|
|
# cursor: 16 del
|