viligen

aladdins_gifts2

Feb 16th, 2022
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def is_crafted_gift(sum_, gifts_table_):
  5.     for min_value, max_value in gifts_table_.keys():
  6.         if min_value <= sum_ <= max_value:
  7.             return gifts_table_[(min_value, max_value)]
  8.  
  9.  
  10. materials_stack = [int(n) for n in input().split()]
  11. magic_level_que = deque([int(n) for n in input().split()])
  12.  
  13. gifts_table = {(100, 199): 'Gemstone',
  14.                (200, 299): 'Porcelain Sculpture',
  15.                (300, 399): 'Gold',
  16.                (400, 499): 'Diamond Jewellery'}
  17.  
  18. crafted_gifts = {'Gemstone': 0, 'Porcelain Sculpture': 0, 'Gold': 0, 'Diamond Jewellery': 0}
  19.  
  20. while materials_stack and magic_level_que:
  21.     current_material, current_magic = materials_stack.pop(), magic_level_que.popleft()
  22.     current_sum = current_material + current_magic
  23.     if current_sum < 100 and current_sum % 2 == 0:
  24.         current_sum = current_material * 2 + current_magic * 3
  25.     elif current_sum < 100:
  26.         current_sum *= 2
  27.     elif current_sum >= 500:
  28.         current_sum /= 2
  29.     current_gift = is_crafted_gift(current_sum, gifts_table)
  30.     if current_gift:
  31.         crafted_gifts[current_gift] += 1
  32.  
  33. if (crafted_gifts['Gemstone'] and crafted_gifts['Porcelain Sculpture']) or \
  34.             (crafted_gifts['Gold'] and crafted_gifts['Diamond Jewellery']):
  35.     print("The wedding presents are made!")
  36. else:
  37.     print("Aladdin does not have enough wedding presents.")
  38.  
  39. if materials_stack:
  40.     print(f"Materials left: {', '.join([str(n) for n in materials_stack])}")
  41. if magic_level_que:
  42.     print(f"Magic left: {', '.join([str(n) for n in magic_level_que])}")
  43.  
  44. for gift, quantity in sorted(crafted_gifts.items()):
  45.     if quantity:
  46.         print(f"{gift}: {quantity}")
  47.  
Advertisement
Add Comment
Please, Sign In to add comment