11b
This commit is contained in:
parent
4a2de10d01
commit
0c6a0075db
25
eleven.py
25
eleven.py
|
@ -6,16 +6,25 @@ m = np.array([[c == '#' for c in l] for l in lines(open(0))]).astype('int')
|
|||
|
||||
for row in range(m.shape[0]-1, -1, -1):
|
||||
if not m[row].any():
|
||||
m = np.concatenate((m[:row+1], m[row:row+1], m[row+1:]), axis=0)
|
||||
m[row] = 2
|
||||
|
||||
for col in range(m.shape[1]-1, -1, -1):
|
||||
if not m[:,col].any():
|
||||
m = np.concatenate((m[:,:col+1], m[:,col:col+1], m[:,col+1:]), axis=1)
|
||||
if not (m[:,col] == 1).any():
|
||||
m[:,col] = 2
|
||||
|
||||
stars = zip(*np.nonzero(m))
|
||||
pairs = combinations(stars, 2)
|
||||
stars = zip(*np.nonzero(m == 1))
|
||||
pairs = list(combinations(stars, 2))
|
||||
|
||||
def dist(a, b):
|
||||
return sum(abs(a[dim] - b[dim]) for dim in (0, 1))
|
||||
def dist(a, b, mul):
|
||||
acc = 0
|
||||
y, x = min(a[0], b[0]), min(a[1], b[1])
|
||||
while y < max(a[0], b[0]):
|
||||
y += 1
|
||||
acc += mul if m[y,x] == 2 else 1
|
||||
while x < max(a[1], b[1]):
|
||||
x += 1
|
||||
acc += mul if m[y,x] == 2 else 1
|
||||
return acc
|
||||
|
||||
print(sum(dist(*p) for p in pairs))
|
||||
print(sum(dist(*p, 2) for p in pairs))
|
||||
print(sum(dist(*p, 1000000) for p in pairs))
|
||||
|
|
Loading…
Reference in New Issue