a.py 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os, argparse
  2. tree = '#'
  3. def hit_function(map, x, y):
  4. wrapped_x = x % len(map[0])
  5. print(wrapped_x)
  6. return map[y][wrapped_x] == tree
  7. def check_stage(map, n):
  8. x = 3*(n+1)
  9. y = n+1
  10. return hit_function(map, x, y)
  11. def solve_task(filename):
  12. toboggan_slope = []
  13. with open(filename) as infile:
  14. for raw_line in infile:
  15. line = raw_line.rstrip()
  16. toboggan_slope.append(line)
  17. trees_hit = 0
  18. for n in range(len(toboggan_slope)-1):
  19. if check_stage(toboggan_slope, n):
  20. trees_hit += 1
  21. print(f"Totally {trees_hit} trees hit")
  22. os.system("pause")
  23. def parse_arguments():
  24. parser = argparse.ArgumentParser(description="Script that solves the case",epilog="Have a nice day!")
  25. parser.add_argument('filename', nargs='?', default="example.txt", help='Input file')
  26. args = parser.parse_args()
  27. return args
  28. def main():
  29. args = parse_arguments()
  30. solve_task(args.filename)
  31. if __name__ == "__main__":
  32. main()