Post

🐹 πŸ”„ 귀도 반 λ‘œμΈμ€ ν¬λ¦¬μŠ€λ§ˆμŠ€λ‚  μ‹¬μ‹¬ν•˜λ‹€κ³  νŒŒμ΄μ¬μ„ λ§Œλ“€μ—ˆλ‹€

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.