You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 anni fa
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import itertools
  2. import sys
  3. from intcode import compute
  4. '''
  5. . . . . . . . . . . . . . . . . . .
  6. . . . . . . . . . . . . . . . . . .
  7. . . . . . . . . . . . . . . . . . .
  8. . . . . . . . # . . . . . . . . . .
  9. |
  10. . . . . . . @-@-#-# . . . . . . . .
  11. |
  12. . . . . . . . . C . . . . . . . . .
  13. |
  14. . . . . . . . @ @-@ . . . . . . . .
  15. | | |
  16. . . . . . . #-#-# #w@w@ . . . . . .
  17. | |
  18. . . . . . . . . Pn@e# # . . . . . .
  19. e
  20. . . . . . . . . . . . . . . . . . .
  21. . . . . . . . . . . . . . . . . . .
  22. '''
  23. text = sys.stdin.read()
  24. code = '''
  25. north
  26. west
  27. take mug
  28. west
  29. take easter egg
  30. east
  31. east
  32. south
  33. south
  34. take asterisk
  35. south
  36. west
  37. north
  38. take jam
  39. south
  40. east
  41. north
  42. east
  43. take klein bottle
  44. south
  45. west
  46. take tambourine
  47. west
  48. take cake
  49. east
  50. south
  51. east
  52. take polygon
  53. north
  54. '''
  55. bytes_ = list(code.lstrip().encode())
  56. items = {line for line in code.splitlines() if line.startswith('take')}
  57. combos = itertools.combinations(sorted(items), 4)
  58. last_line = ''
  59. history = ''
  60. for c in map(chr, compute(text, iter(bytes_))):
  61. history += c
  62. if history.endswith('== Security Checkpoint =='):
  63. take = next(combos)
  64. drop = items.difference(take)
  65. instructions = '\n'.join(
  66. [line for line in take] +
  67. [line.replace('take', 'drop') for line in drop] +
  68. ['east\n']
  69. )
  70. bytes_.extend(instructions.encode())
  71. print(history.splitlines()[-1])