Skip to content

Instantly share code, notes, and snippets.

@loudambiance
Created December 16, 2021 23:45
Show Gist options
  • Save loudambiance/fec948c039a770f494b243bae4819a92 to your computer and use it in GitHub Desktop.
Save loudambiance/fec948c039a770f494b243bae4819a92 to your computer and use it in GitHub Desktop.
import numpy
coords = []
grid = numpy.zeros((1000, 1000))
with open('task5.txt') as f:
lines = f.read().splitlines()
for line in lines:
coords.append(line.split(' -> '))
for coord in coords:
coord1 = coord[0].split(',')
coord2 = coord[1].split(',')
if coord1[0] == coord2[0]:
x = int(coord1[0])
large_y = int(coord1[1]) if int(coord2[1]) <= int(coord1[1]) else int(coord2[1])
small_y = int(coord1[1]) if int(coord2[1]) >= int(coord1[1]) else int(coord2[1])
for y in range(small_y,large_y+1):
grid[x][y] += 1
elif coord1[1] == coord2[1]:
y = int(coord1[1])
large_x = int(coord1[0]) if int(coord2[0]) <= int(coord1[0]) else int(coord2[0])
small_x = int(coord1[0]) if int(coord2[0]) >= int(coord1[0]) else int(coord2[0])
for x in range(small_x,large_x+1):
grid[x][y] += 1
print(grid)
print((grid >= 2).sum())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment