a.py 1.0 KB

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