Skip to content

Instantly share code, notes, and snippets.

@vjeranc
Last active December 11, 2023 11:35
Show Gist options
  • Save vjeranc/fafec7ab7cbfbc6b5dd06566bb775ffe to your computer and use it in GitHub Desktop.
Save vjeranc/fafec7ab7cbfbc6b5dd06566bb775ffe to your computer and use it in GitHub Desktop.
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