-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntcode.py
More file actions
61 lines (46 loc) · 1.38 KB
/
Intcode.py
File metadata and controls
61 lines (46 loc) · 1.38 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# before made intcode into a class
# probably broke something
# dab on the haters 2019
import csv
point = 0
opcodes = [1, 2, 3, 4, 99]
av = []
modes = ["position", "immediate"]
def load(file):
with open(file) as csvfile:
adventreader = csv.reader(csvfile, delimiter=",")
av = list(map(int, adventreader[0]))
return av
def go():
while point < len(av):
strpt = str(point)
for i in len("%i" % point):
if av[point] < 100:
if av[point] in opcodes:
if av[point] == opcodes[0]:
add(point)
elif av[point] == opcodes[1]:
mult(point)
elif av[point] == opcodes[2]:
store[point]
elif av[point] == opcodes[3]:
pull[point]
elif av[point] == opcodes[4]:
print("point:")
print(point)
def get_digit(number, n):
return number // 10 ** n % 10
def add(point):
sum = av[point + 3]
av[sum] = av[av[point + 1]] + av[av[point + 2]]
point += 4
def mult(point):
a = av[point + 3]
av[a] = av[av[point + 1]] * av[av[point + 2]]
point += 4
def store(point):
storage = av[point + 1]
av[av[storage]] = input("input:")
def pull(point):
output = av[point + 1]
print(output)