x = 0
y = 0
direction = 0
lidar_direction = 0

DIRECTIONS = {
    0: (0, -1),
    1: (1, -1),
    2: (1, 0),
    3: (1, 1),
    4: (0, 1),
    5: (-1, 1),
    6: (-1, 0),
    7: (-1, -1),
}


walls = {}

with open("lidar-log.txt") as file:
    log = []
    for line in file:
        line = line.strip()
        if line == "boop":
            log.append(line)
        else:
            log.append(int(line))

i = 0
steps = 0
while i < len(log):
    steps += 1
    is_boop = i < len(log) - 1 and log[i + 1] == "boop"
    if not is_boop:
        dx, dy = DIRECTIONS[direction]
        x += dx
        y += dy

    if is_boop:
        direction = (direction + 2) % 8

    dx, dy = DIRECTIONS[lidar_direction]
    dist = log[i]
    if (x + dx * dist, y + dy * dist) not in walls:
        walls[x + dx * dist, y + dy * dist] = steps

    lidar_direction = (lidar_direction + 1) % 8

    if is_boop:
        i += 2
    else:
        i += 1

min_x = min(wall[0] for wall in walls)
min_y = min(wall[1] for wall in walls)
max_x = max(wall[0] for wall in walls)
max_y = max(wall[1] for wall in walls)


for y in range(min_y, max_y + 1):
    for x in range(min_x, max_x + 1):
        if (x, y) in walls:
            print("#", end="")
        else:
            print(".", end="")
    print()

print(len(walls))
print(max(walls.values()))
