# ==============================================================================
"""BINO : compute the binomial coefficient C(n,p)"""
# ==============================================================================
__author__  = "Philippe Blasi"
__version__ = "1.0" # import factorial function from previous example
__date__    = "2026-02-25"
__usage__   = """
User input : <n>,<p> (where n:int >= 0, p:int >= 0)
App output : binomial coefficient C(n,p)"""
# ==============================================================================
from ezCLI import *
from A1_ite_facto import facto
# ------------------------------------------------------------------------------
def bino(n:int, p:int) -> int:
  """compute the binomial coefficient C(n,p) using standard factorial"""
  return facto(n)//(facto(p)*facto(n-p))
# ------------------------------------------------------------------------------
def parser(command:str) -> str:
  """parse 'command' as 'n,p' before calling 'bino(n,p)'"""
  # recupérer les valeurs
  param = parse(command)
  # verifier qu'il n'y en a que deux
  assert len(param) == 2, "two comma separated values mut be provided"
  # récupérer la première
  n = param[0]
  # vérifier que c'est un entier positif
  assert type(n) is int and n >= 0, "<n> must be a positive integer"
  # récupérer la seconde
  p = param[1]
  # vérifier que c'est un entier positif
  assert type(p) is int and p >= 0, "<p> must be a positive integer"
  
  return f"bino({n,p}) = {bino(n,p)}" 
# ==============================================================================
if __name__ == '__main__':
  userloop(parser, "Enter <n>,<p>")
# ==============================================================================
