Skip to content

Commit e5b6c45

Browse files
committed
refactored indexes
1 parent bc040a3 commit e5b6c45

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

5.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def compute(arg: List[int]) -> List[int]:
1616
idx = 0
1717
for _ in range(nInstr):
1818
opcode = '0'+str(arg[idx])
19-
if len(opcode) > 2:
19+
if len(opcode) > 3:
2020
isV3immediate, isV2immediate, isV1immediate = [
21-
bool(x) for x in opcode]
21+
bool(x) for x in opcode[0:3]]
2222
opcode = int(opcode[3:])
2323
else:
2424
opcode = int(opcode)
@@ -38,11 +38,13 @@ def compute(arg: List[int]) -> List[int]:
3838
idx += 4
3939
elif isInput(opcode):
4040
''' Special Input Case'''
41+
valIdx = arg[idx+1]
4142
specialInput = int(1)
42-
arg[val1idx] = specialInput
43+
arg[valIdx] = specialInput
4344
idx += 2
4445
elif isOutput(opcode):
45-
print(arg[idx+1])
46+
valIdx = arg[idx+1]
47+
print(arg[valIdx])
4648
idx += 2
4749
else:
4850
raise Exception('no valid opcode')
@@ -89,5 +91,5 @@ def isAddtion(opcode):
8991
# break
9092

9193

92-
# Intcode = open('5-in.txt').read().split(',')
93-
# print(Intcode)
94+
Intcode = open('5-in.txt').read().split(',')
95+
print(compute(Intcode))

0 commit comments

Comments
 (0)