Advertisement
go6odn28

milkshakes_3

May 20th, 2024
159
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 1 0
  1. from collections import deque
  2.  
  3.  
  4. def process_chocolate_and_milk(choc, milk, chocs, milks):
  5.     conditions = {
  6.         (True, True): lambda: None,  # both are <= 0
  7.         (True, False): lambda: milks.appendleft(milk),  # chocolate <= 0
  8.         (False, True): lambda: chocs.append(choc),  # milk <= 0
  9.         (False, False): lambda: None,  # neither are <= 0
  10.     }
  11.     conditions[(choc <= 0, milk <= 0)]()
  12.  
  13.  
  14. def make_milkshake(choc, milk, chocs, milks, shakes):
  15.     if choc == milk:
  16.         shakes += 1
  17.     else:
  18.         milks.append(milk)
  19.         choc -= 5
  20.         chocs.append(choc)
  21.     return shakes
  22.  
  23.  
  24. chocs = [int(x) for x in input().split(", ")]
  25. milks = deque([int(x) for x in input().split(", ")])
  26.  
  27. shakes = 0
  28.  
  29. while milks and chocs:
  30.     if shakes == 5:
  31.         break
  32.     choc = chocs.pop()
  33.     milk = milks.popleft()
  34.  
  35.     if choc <= 0 or milk <= 0:
  36.         process_chocolate_and_milk(choc, milk, chocs, milks)
  37.     else:
  38.         shakes = make_milkshake(choc, milk, chocs, milks, shakes)
  39.  
  40. print("Great! You made all the chocolate milkshakes needed!") if shakes == 5 else print("Not enough milkshakes.")
  41. print(f"Chocolate: {', '.join([str(x) for x in chocs])}") if chocs else print("Chocolate: empty")
  42. print(f"Milk: {', '.join([str(x) for x in milks])}") if milks else print("Milk: empty")
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement