πΉ π κ·λ λ° λ‘μΈμ ν¬λ¦¬μ€λ§μ€λ μ¬μ¬νλ€κ³ νμ΄μ¬μ λ§λ€μλ€
1. λ¬Έμ λ§ν¬
6568λ²: κ·λ λ° λ‘μΈμ ν¬λ¦¬μ€λ§μ€λ μ¬μ¬νλ€κ³ νμ΄μ¬μ λ§λ€μλ€
2. μ½λ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
adder = 0
pc = 0
memory = []
for _ in range(32):
memory.append(int(input(), 2))
while True:
now = memory[pc]
command = now // 32
operand = now % 32
pc = (pc + 1) % 32
# λ©λͺ¨λ¦¬ μ£Όμ xμ κ°μ°κΈ°μ κ°μ μ μ₯νλ€.
if command == 0:
memory[operand] = adder
# λ©λͺ¨λ¦¬ μ£Όμ xμ κ°μ κ°μ°κΈ°λ‘ λΆλ¬μ¨λ€.
elif command == 1:
adder = memory[operand]
# κ°μ°κΈ°μ κ°μ΄ 0μ΄λ©΄ PCκ°μ xλ‘ λ°κΎΌλ€.
elif command == 2:
if adder == 0:
pc = operand
# μ무 μ°μ°λ νμ§ μλλ€.
elif command == 3:
pass
# κ°μ°κΈ° κ°μ 1 κ°μμν¨λ€.
elif command == 4:
adder = (adder + 255) % 256
# κ°μ°κΈ° κ°μ 1 μ¦κ°μν¨λ€.
elif command == 5:
adder = (adder + 1) % 256
# PC κ°μ xλ‘ λ°κΎΌλ€.
elif command == 6:
pc = operand
# νλ‘κ·Έλ¨μ μ’
λ£νλ€.
elif command == 7:
break
print(bin(adder % 256)[2:])
This post is licensed under CC BY 4.0 by the author.