13 KiB
13 KiB
In [ ]:
In [ ]:
def puissance(x:float, n:int) -> float:
""" n must be >= 0
>>> puissance(0,0)
1
>>> puissance(1,0)
1
>>> puissance(1,1)
1
>>> puissance(1,3)
1
>>> puissance(2,3)
8
>>> puissance(10,5)
100000
"""
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, verbose = False)In [ ]:
In [ ]:
In [ ]:
def syracuse(u0: int, n: int) -> int:
""" Return Syracuse suite value
u0 must be > 0 ; n must be >= 0
>>> syracuse(1, 0)
1
>>> syracuse(15, 7)
160
>>> syracuse(15, 4)
35
>>> syracuse(15, 17)
1
"""
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, verbose = False)In [ ]:
In [ ]:
In [ ]:
In [ ]:
def find_dicho_recur(liste: list, value: int) -> bool:
""" liste must be sorted
>>> find_dicho_recur([], 0)
False
>>> find_dicho_recur([1], 0)
False
>>> find_dicho_recur([1], 1)
True
>>> find_dicho_recur([1, 2], 1)
True
>>> find_dicho_recur([1, 2], 2)
True
>>> find_dicho_recur([1, 2], 3)
False
>>> find_dicho_recur([1, 2], -1)
False
>>> find_dicho_recur([1,2,3], 0)
False
>>> find_dicho_recur([1,2,3], 5)
False
>>> find_dicho_recur([1,2,3], 1)
True
>>> find_dicho_recur([1,2,3], 2)
True
>>> find_dicho_recur([1,2,3], 3)
True
>>> find_dicho_recur([1,2,3,4], 1)
True
>>> find_dicho_recur([1,2,3,4], 2)
True
>>> find_dicho_recur([1,2,3,4], 3)
True
>>> find_dicho_recur([1,2,3,4], 4)
True
>>> find_dicho_recur([1,2,3,4], -1)
False
>>> find_dicho_recur([1,2,3,4], 10)
False
"""
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, verbose = False)In [ ]:
def rendu_monnaie(pieces: list, somme: int) -> list:
""" Return optimal coin's count for money back
Return None if no solution exists
pieces : list of int
>>> rendu_monnaie([], 5) is None
True
>>> rendu_monnaie([4,3], 1) is None
True
>>> rendu_monnaie([4,3], -1) is None
True
>>> rendu_monnaie([4,3], 5) is None
True
>>> rendu_monnaie([4,3], 6)
[3, 3]
>>> rendu_monnaie([4,3], 8)
[4, 4]
>>> rendu_monnaie([4,3,1], 6)
[3, 3]
>>> rendu_monnaie([4,3,1], 5)
[4, 1]
"""
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, verbose = False)In [ ]:
def rendu_dyn(pieces: list, somme: int) -> list:
""" Return optimal coin's count for money back
Return [] if no solution exists
pieces : list of POSITIVE int
>>> rendu_dyn([], 5)
[]
>>> rendu_dyn([4,3], 1)
[]
>>> rendu_dyn([4,3], 0)
[]
>>> rendu_dyn([4,3], 5)
[]
>>> rendu_dyn([4,3], 6)
[3, 3]
>>> rendu_dyn([4,3], 8)
[4, 4]
>>> rendu_dyn([4,3,1], 6)
[3, 3]
>>> rendu_dyn([4,3,1], 5)
[4, 1]
"""
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, verbose = False)