File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,9 @@ def compute(arg: List[int]) -> List[int]:
16
16
idx = 0
17
17
for _ in range (nInstr ):
18
18
opcode = '0' + str (arg [idx ])
19
- if len (opcode ) > 2 :
19
+ if len (opcode ) > 3 :
20
20
isV3immediate , isV2immediate , isV1immediate = [
21
- bool (x ) for x in opcode ]
21
+ bool (x ) for x in opcode [ 0 : 3 ] ]
22
22
opcode = int (opcode [3 :])
23
23
else :
24
24
opcode = int (opcode )
@@ -38,11 +38,13 @@ def compute(arg: List[int]) -> List[int]:
38
38
idx += 4
39
39
elif isInput (opcode ):
40
40
''' Special Input Case'''
41
+ valIdx = arg [idx + 1 ]
41
42
specialInput = int (1 )
42
- arg [val1idx ] = specialInput
43
+ arg [valIdx ] = specialInput
43
44
idx += 2
44
45
elif isOutput (opcode ):
45
- print (arg [idx + 1 ])
46
+ valIdx = arg [idx + 1 ]
47
+ print (arg [valIdx ])
46
48
idx += 2
47
49
else :
48
50
raise Exception ('no valid opcode' )
@@ -89,5 +91,5 @@ def isAddtion(opcode):
89
91
# break
90
92
91
93
92
- # Intcode = open('5-in.txt').read().split(',')
93
- # print(Intcode)
94
+ Intcode = open ('5-in.txt' ).read ().split (',' )
95
+ print (compute ( Intcode ) )
You can’t perform that action at this time.
0 commit comments