Update
Browse files
app.py
CHANGED
@@ -42,20 +42,16 @@ def solve(file_obj):
|
|
42 |
total += X * cycle
|
43 |
X += int(line.split()[-1])
|
44 |
sprite = X
|
45 |
-
|
46 |
-
|
47 |
-
cycle = cycle % DISPLAY_WIDTH
|
48 |
|
49 |
-
print("Solution to part 1: ", total)
|
50 |
res = "\n".join(["".join(crt[i:i+DISPLAY_WIDTH]) for i in range(0, len(crt), DISPLAY_WIDTH)])
|
51 |
-
print("Solution to part 2:")
|
52 |
print(res)
|
53 |
-
|
54 |
-
|
55 |
# Bonus: make an image and then use OCR
|
56 |
# to extract the text.
|
57 |
-
img = np.array(crt)
|
58 |
-
|
59 |
plt.imshow(img, cmap="binary")
|
60 |
plt.axis('off')
|
61 |
plt.savefig("day_10.png")
|
|
|
42 |
total += X * cycle
|
43 |
X += int(line.split()[-1])
|
44 |
sprite = X
|
45 |
+
# Go back to first position after 40 pixels
|
46 |
+
cycle = cycle % DISPLAY_WIDTH
|
|
|
47 |
|
48 |
+
# print("Solution to part 1: ", total)
|
49 |
res = "\n".join(["".join(crt[i:i+DISPLAY_WIDTH]) for i in range(0, len(crt), DISPLAY_WIDTH)])
|
|
|
50 |
print(res)
|
51 |
+
|
|
|
52 |
# Bonus: make an image and then use OCR
|
53 |
# to extract the text.
|
54 |
+
img = np.array([[c.replace(PIXEL, 1).replace(EMPTY, 0) for c in crt[i:i+DISPLAY_WIDTH]] for i in range(0, len(crt), DISPLAY_WIDTH)) ])
|
|
|
55 |
plt.imshow(img, cmap="binary")
|
56 |
plt.axis('off')
|
57 |
plt.savefig("day_10.png")
|