Day 10: draw asteroid field
This commit is contained in:
parent
39090d4e94
commit
61ec46dcf3
|
@ -3,6 +3,9 @@ import math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
DIM = 40
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
with open("day10.txt", "rt") as input_file:
|
with open("day10.txt", "rt") as input_file:
|
||||||
amap = [line.rstrip() for line in input_file.readlines()]
|
amap = [line.rstrip() for line in input_file.readlines()]
|
||||||
|
@ -13,6 +16,7 @@ def main():
|
||||||
if value == "#":
|
if value == "#":
|
||||||
asteroids.append((x, y))
|
asteroids.append((x, y))
|
||||||
|
|
||||||
|
# Part 1
|
||||||
best_vis = 0
|
best_vis = 0
|
||||||
best_pos = None
|
best_pos = None
|
||||||
for pos in asteroids:
|
for pos in asteroids:
|
||||||
|
@ -20,6 +24,20 @@ def main():
|
||||||
if vis > best_vis:
|
if vis > best_vis:
|
||||||
best_vis, best_pos = vis, pos
|
best_vis, best_pos = vis, pos
|
||||||
print(f"Best visibility is {best_vis} at {best_pos}.")
|
print(f"Best visibility is {best_vis} at {best_pos}.")
|
||||||
|
draw(asteroids, best_pos)
|
||||||
|
|
||||||
|
def draw(asteroids, station_pos):
|
||||||
|
for y in range(DIM):
|
||||||
|
print(str(y).zfill(2), end=" ")
|
||||||
|
for x in range(DIM):
|
||||||
|
if (x, y) == station_pos:
|
||||||
|
print("@", end="")
|
||||||
|
elif (x, y) in asteroids:
|
||||||
|
print("█", end="")
|
||||||
|
else:
|
||||||
|
print(" ", end="")
|
||||||
|
print()
|
||||||
|
print(" " + "0123456789"*4)
|
||||||
|
|
||||||
def num_visible_asts(asts, ref):
|
def num_visible_asts(asts, ref):
|
||||||
asts = asts.copy()
|
asts = asts.copy()
|
||||||
|
|
Loading…
Reference in a new issue