Jan 27th, 2022
840
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from collections import deque
2. from math import ceil
3.
4.
5. required_values = {tuple(range(100, 200)): 'Gemstone', tuple(range(200, 300)): 'Porcelain Sculpture',
6.                    tuple(range(300, 400)): 'Gold',
7.                    tuple(range(400, 500)): 'Diamond Jewellery'}
9.
10. materials_stack = [int(n) for n in input().split()]
11. magic_que = deque([int(n) for n in input().split()])
12.
13. while materials_stack and magic_que:
14.     current_material, current_magic = materials_stack[-1], magic_que[0]
15.     current_result = (current_material + current_magic)
16.     is_crafted = False
17.     while True:
18.         if current_result < 100:
19.             if current_result % 2 == 0:
20.                 current_result = (current_material * 2 + current_magic * 3)
21.             else:
22.                 current_result *= 2
23.             if 99 < current_result < 500:
24.                 continue
25.             else:
26.                 materials_stack.pop()
27.                 magic_que.popleft()
28.                 break
29.         elif current_result > 499:
30.             current_result = ceil(current_result/2)
31.             if 99 < current_result < 500:
32.                 continue
33.             else:
34.                 materials_stack.pop()
35.                 magic_que.popleft()
36.                 break
37.
38.         for tpl in required_values.keys():
39.             if current_result in tpl:
44.                 materials_stack.pop()
45.                 magic_que.popleft()
46.                 is_crafted = True
47.                 break
48.         if is_crafted:
49.             break
50.
53.     print("The wedding presents are made!")
54. else:
55.     print("Aladdin does not have enough wedding presents.")
56.
57. if materials_stack:
58.     print(f"Materials left: {', '.join([str(n) for n in materials_stack])}")
59. if magic_que:
60.     print(f"Magic left: {', '.join([str(n) for n in magic_que])}")
61.