瀏覽代碼

💫

master
Roderic Day 5 年之前
父節點
當前提交
7bbb2b04c2
共有 1 個文件被更改,包括 82 次插入0 次删除
  1. +82
    -0
      y2019/p25.py

+ 82
- 0
y2019/p25.py 查看文件

@@ -0,0 +1,82 @@
import itertools
import sys

from intcode import compute


'''
. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . # . . . . . . . . . .
|
. . . . . . @-@-#-# . . . . . . . .
|
. . . . . . . . C . . . . . . . . .
|
. . . . . . . @ @-@ . . . . . . . .
| | |
. . . . . . #-#-# #w@w@ . . . . . .
| |
. . . . . . . . Pn@e# # . . . . . .
e
. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

'''

text = sys.stdin.read()

code = '''
north
west
take mug
west
take easter egg
east
east
south
south
take asterisk
south
west
north
take jam
south
east
north
east
take klein bottle
south
west
take tambourine
west
take cake
east
south
east
take polygon
north
'''

bytes_ = list(code.lstrip().encode())
items = {line for line in code.splitlines() if line.startswith('take')}
combos = itertools.combinations(sorted(items), 4)
last_line = ''
history = ''
for c in map(chr, compute(text, iter(bytes_))):
history += c
if history.endswith('== Security Checkpoint =='):
take = next(combos)
drop = items.difference(take)
instructions = '\n'.join(
[line for line in take] +
[line.replace('take', 'drop') for line in drop] +
['east\n']
)
bytes_.extend(instructions.encode())
print(history.splitlines()[-1])

Loading…
取消
儲存