Noëlle 4 anos atrás
pai
commit
581490ecaa
1 arquivos alterados com 28 adições e 0 exclusões
  1. 28
    0
      day3b.py

+ 28
- 0
day3b.py Ver arquivo

@@ -0,0 +1,28 @@
from functools import reduce

def main():
with open("input3.txt") as file:
lines = file.readlines()
grid = [list(line.strip()) for line in lines]
print(grid[0])
wrap = len(grid[0])
treebumps = []
routes = [[1,1],[3,1],[5,1],[7,1],[1,2]]
for route in routes:
coords = [0,0] # x, y - across, down
trees = 0
while coords[1] < len(grid):
if grid[coords[1]][coords[0]] == "#":
trees += 1
coords[0] = coords[0] + route[0]
coords[1] = coords[1] + route[1]
if coords[0] >= wrap:
coords[0] = coords[0] - wrap
print(f"It's been a long toboggan trip going {route[0]} right and {route[1]} down, and I encountered {trees} trees.")
treebumps.append(trees)
total = reduce((lambda x,y: x*y), treebumps)
print(f"I encountered these trees: {treebumps} - those produce {total}.")


if __name__ == "__main__":
main()

Carregando…
Cancelar
Salvar