Solve easy d19 2019 because I need stars
This commit is contained in:
20
2019/d9.py
20
2019/d9.py
@@ -2,9 +2,9 @@ from lib import get_data, str_to_ints
|
||||
|
||||
|
||||
class Amp:
|
||||
def __init__(self, xs):
|
||||
def __init__(self, xs, buffer_extra=10000):
|
||||
self.xs = list(xs)
|
||||
self.xs += [0 for _ in range(10000)]
|
||||
self.xs += [0 for _ in range(buffer_extra)]
|
||||
self.i = 0
|
||||
self.inputs = []
|
||||
self.outputs = []
|
||||
@@ -41,12 +41,6 @@ class Amp:
|
||||
else:
|
||||
assert False
|
||||
|
||||
def go_all(self):
|
||||
while not self.done:
|
||||
self.go()
|
||||
while self.outputs:
|
||||
print(self.pop(), end=",")
|
||||
|
||||
def go(self):
|
||||
xs = self.xs
|
||||
i = self.i
|
||||
@@ -138,11 +132,17 @@ def part_1(data):
|
||||
|
||||
a = Amp(xs_orig)
|
||||
a.feed(1)
|
||||
a.go_all()
|
||||
while not a.done:
|
||||
a.go()
|
||||
a.go()
|
||||
print(a.pop())
|
||||
|
||||
a = Amp(xs_orig)
|
||||
a.feed(2)
|
||||
a.go_all()
|
||||
while not a.done:
|
||||
a.go()
|
||||
a.go()
|
||||
print(a.pop())
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user