Solve easy d19 2019 because I need stars
This commit is contained in:
52
2019/d19.py
Normal file
52
2019/d19.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from lib import get_data, str_to_ints
|
||||
from d9 import Amp
|
||||
|
||||
|
||||
def isin(xs, x, y):
|
||||
a = Amp(xs, 100)
|
||||
a.feed(x)
|
||||
a.feed(y)
|
||||
a.go()
|
||||
return a.pop()
|
||||
|
||||
|
||||
def part_1(data):
|
||||
xs = str_to_ints(data)
|
||||
r = 0
|
||||
for y in range(50):
|
||||
for x in range(50):
|
||||
o = isin(xs, x, y)
|
||||
if o == 1:
|
||||
print("#", end="")
|
||||
else:
|
||||
print(" ", end="")
|
||||
r += o
|
||||
print()
|
||||
print(r)
|
||||
|
||||
|
||||
def part_2(data):
|
||||
xs = str_to_ints(data)
|
||||
off = 99
|
||||
x, y = 3, 4
|
||||
while True:
|
||||
y += 1
|
||||
while True:
|
||||
o = isin(xs, x, y)
|
||||
if o == 1:
|
||||
break
|
||||
x += 1
|
||||
|
||||
if isin(xs, x, y - off) and isin(xs, x + off, y - off) and isin(xs, x + off, y):
|
||||
print(x * 10_000 + y - off)
|
||||
break
|
||||
|
||||
|
||||
def main():
|
||||
data = get_data(__file__)
|
||||
part_1(data)
|
||||
part_2(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user