Last active
December 11, 2023 11:35
-
-
Save vjeranc/fafec7ab7cbfbc6b5dd06566bb775ffe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collect(u): | |
ri, i = [], 0 | |
for r in u: | |
n = r.count('#') | |
if n: ri.extend([i]*n) | |
i += 1 if n else D | |
return ri | |
D = 1000000 # 2 # for part 1 | |
manhattan_sum = lambda xs: sum((1+i+i-len(xs))*x for i, x in enumerate(xs)) | |
u = [[*l.strip()] for l in open(0)] | |
print(sum(map(manhattan_sum, (collect(u), collect(zip(*u)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment