Started with 2020 because I need stars for Beeminder
This commit is contained in:
33
2020/d3.py
Normal file
33
2020/d3.py
Normal 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()
|
||||
Reference in New Issue
Block a user