Advertisement
Nenogzar

01_aladdin's_gifts

Jun 4th, 2024
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. materials = list(map(int, input().split()))
  5. magic_levels = deque(map(int, input().split()))
  6.  
  7.  
  8. presents = {
  9.     "Gemstone": [100, 199],
  10.     "Porcelain Sculpture": [200, 299],
  11.     "Gold": [300, 399],
  12.     "Diamond Jewellery": [400, 499],
  13. }
  14.  
  15.  
  16. items = {}
  17.  
  18.  
  19. def sum_item(material, magic):
  20.     return material + magic
  21.  
  22.  
  23. def check_dict(result):
  24.     for key, value in presents.items():
  25.         start, end = value
  26.         if result in range(start, end + 1):
  27.             if key not in items:
  28.                 items[key] = 1
  29.             else:
  30.                 items[key] += 1
  31.             return True
  32.  
  33.  
  34. while materials and magic_levels:
  35.     material = materials.pop()
  36.     magic = magic_levels.popleft()
  37.     result = sum_item(material, magic)
  38.  
  39.     if not check_dict(result):
  40.         if result < 100:
  41.             if result % 2 == 0:
  42.                 material *= 2
  43.                 magic *= 3
  44.                 result = sum_item(material, magic)
  45.                 check_dict(result)
  46.             else:
  47.                 result *= 2
  48.                 check_dict(result)
  49.         elif result > 499:
  50.             result //= 2
  51.             check_dict(result)
  52.  
  53. crafted_presents = True
  54. for present in presents.keys():
  55.     if present not in items:
  56.         crafted_presents = False
  57.         break
  58.  
  59.  
  60. if crafted_presents:
  61.     print("The wedding presents are made!")
  62. else:
  63.     print("Aladdin does not have enough wedding presents.")
  64.  
  65.  
  66. if materials:
  67.     print(f"Materials left: {', '.join(map(str, materials))}")
  68. if magic_levels:
  69.     print(f"Magic left: {', '.join(map(str, magic_levels))}")
  70.  
  71.  
  72. for key in sorted(items):
  73.     print(f"{key}: {items[key]}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement