Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728
  1. from functools import reduce
  2. def main():
  3. with open("input3.txt") as file:
  4. lines = file.readlines()
  5. grid = [list(line.strip()) for line in lines]
  6. print(grid[0])
  7. wrap = len(grid[0])
  8. treebumps = []
  9. routes = [[1,1],[3,1],[5,1],[7,1],[1,2]]
  10. for route in routes:
  11. coords = [0,0] # x, y - across, down
  12. trees = 0
  13. while coords[1] < len(grid):
  14. if grid[coords[1]][coords[0]] == "#":
  15. trees += 1
  16. coords[0] = coords[0] + route[0]
  17. coords[1] = coords[1] + route[1]
  18. if coords[0] >= wrap:
  19. coords[0] = coords[0] - wrap
  20. print(f"It's been a long toboggan trip going {route[0]} right and {route[1]} down, and I encountered {trees} trees.")
  21. treebumps.append(trees)
  22. total = reduce((lambda x,y: x*y), treebumps)
  23. print(f"I encountered these trees: {treebumps} - those produce {total}.")
  24. if __name__ == "__main__":
  25. main()