Skip to content

Instantly share code, notes, and snippets.

@edg-l

edg-l/day3_a.py Secret

Last active December 3, 2021 07:51
Show Gist options
  • Save edg-l/cea2641b00e69ccc633fe3f6398a1fd0 to your computer and use it in GitHub Desktop.
Save edg-l/cea2641b00e69ccc633fe3f6398a1fd0 to your computer and use it in GitHub Desktop.
aoc day 3 a
with open("input.txt", "r") as f:
r = None
for l in f.read().splitlines():
if r is None:
r = [[0, 0] for i in range(len(l))]
for i, x in enumerate(l):
r[i][x == "1"] += 1
gamma, epsilon = 0, 0
for i, (a, b) in enumerate(r[::-1]):
if a > b:
epsilon |= 1 << i
else:
gamma |= 1 << i
print(gamma * epsilon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment