Started with 2020 because I need stars for Beeminder

This commit is contained in:
2024-08-19 09:42:10 -04:00
parent 6b0d7057d1
commit 04d8c44d66
6 changed files with 108 additions and 0 deletions

33
2020/d3.py Normal file
View File

@@ -0,0 +1,33 @@
from lib import get_data, Grid2D
def part_1(data):
g = Grid2D(data)
pos = (0, 0)
r = 0
while pos[0] < g.n_rows:
if g[pos] == "#":
r += 1
pos = (pos[0] + 1, (pos[1] + 3) % g.n_cols)
print(r)
fr = 1
for dr, dc in [(1, 1), (1, 3), (1, 5), (1, 7), (2, 1)]:
pos = (0, 0)
r = 0
while pos[0] < g.n_rows:
if g[pos] == "#":
r += 1
pos = (pos[0] + dr, (pos[1] + dc) % g.n_cols)
fr *= r
print(fr)
def main():
data = get_data(__file__)
part_1(data)
if __name__ == "__main__":
main()