Advertisement
Guest User

Untitled

a guest
Aug 16th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. from collections import deque
  2.  
  3. materials = [int(x) for x in input().split()]
  4. #print(materials)
  5. magic_level = deque(int(x) for x in input().split())
  6. #print(magic_level)
  7.  
  8. pattern = {
  9. 150: 'Doll',
  10. 250: 'Wooden train',
  11. 300: 'Teddy bear',
  12. 400: 'Bicycle',
  13. }
  14.  
  15. counters = {}
  16.  
  17. total_magic_lvl: int = 0
  18.  
  19. while True:
  20. if not materials or not magic_level:
  21. break
  22. material = materials.pop()
  23. m_lvl = magic_level.popleft()
  24. total_magic_lvl = material * m_lvl
  25. if total_magic_lvl > 0:
  26. if total_magic_lvl in pattern.keys():
  27. if pattern[total_magic_lvl] not in counters.keys():
  28. counters[pattern[total_magic_lvl]] = 1
  29. continue
  30. counters[pattern[total_magic_lvl]] += 1
  31. else:
  32. # If the product of the operation is a negative number, then you have to sum the values together,
  33. # remove them both from their positions and the result should be added to the materials.
  34. if total_magic_lvl < 0:
  35. result_after_negative_total_magic_lvl = material + m_lvl
  36. materials.append(result_after_negative_total_magic_lvl)
  37.  
  38. # If the product doesn’t equal one of the magic levels in the table and is a positive number,
  39. # remove only the magic value and increase the material value with 15.
  40. if total_magic_lvl > 0:
  41. material += 15
  42. materials.append(material)
  43.  
  44. # If the magic or material (or both) equals 0,
  45. # remove it (or both) and continue crafting the presents.
  46. if total_magic_lvl == 0:
  47. if material != 0:
  48. materials.append(material)
  49. if m_lvl != 0:
  50. magic_level.appendleft(m_lvl)
  51. else:
  52. # If the product of the operation is a negative number, then you have to sum the values together,
  53. # remove them both from their positions and the result should be added to the materials.
  54. if total_magic_lvl < 0:
  55. result_after_negative_total_magic_lvl = material + m_lvl
  56. materials.append(result_after_negative_total_magic_lvl)
  57.  
  58. # If the product doesn’t equal one of the magic levels in the table and is a positive number,
  59. # remove only the magic value and increase the material value with 15.
  60. elif total_magic_lvl > 0:
  61. material += 15
  62. materials.append(material)
  63.  
  64. # If the magic or material (or both) equals 0,
  65. # remove it (or both) and continue crafting the presents.
  66. else:
  67. if material:
  68. materials.append(material)
  69. elif m_lvl:
  70. magic_level.appendleft(m_lvl)
  71.  
  72. if 'Doll' and 'Wooden train' in counters.keys() or 'Teddy bear' and 'Bicycle' in counters.keys():
  73. print("The presents are crafted! Merry Christmas!")
  74. else:
  75. print("No presents this Christmas!")
  76. if materials or magic_level:
  77. materials = materials[::-1]
  78. if materials:
  79. print(f"Materials left: {', '.join(str(x) for x in materials)}")
  80. if magic_level:
  81. print(f"Magic left: {', '.join(str(x) for x in magic_level)}")
  82. #On the next lines print the presents you have crafted at least once, ordered alphabetically in the format:
  83. #"{toy name}: {amount}"
  84.  
  85. #print(counters)
  86.  
  87. for key, value in sorted(counters.items(), key=lambda x: x[0]):
  88. print(f"{key}: {value}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement