Write the function optimal_gifts(gifts: int, recipients: int) -> int
You are given gifts number of gifts and recipients number of recipients.

Return the maximum number of recipients that can receive 8 gifts under the following conditions:

  • No recipient can recieve no gifts
  • No recipient can recieve 4 gifts
  • No recipient can receive more than 8 gifts
  • All gifts must be distibuted unless all recipients are already recveiving 8 gifts

Examples:

  • optimal_gifts(8, 2) returns 0
  • optimal_gifts(12, 2) returns 0
  • optimal_gifts(8, 1) returns 1
  • optimal_gifts(24, 2) returns 2
  • optimal_gifts(24, 3) returns 3
  • optimal_gifts(24, 4) returns 2
def optimal_gifts(gifts: int, recipients: int) -> int:
    kids = [1 for _ in range(gifts)]
    gifts -= recipients
    for i in range(recipients):
        while (gifts > 0 and kids[i] < 8):
            kids[i] += 1
            gifts -= 1

    eigths = sum([1 if kid == 8 else 0 for kid in kids])

    if 4 in kids:
        eigths -= 1
        
    return eigths