Advertisement
ralig

Advent Of Code 2020 Day 3 Part 1

Dec 3rd, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. from pathlib import Path
  2.  
  3. cntTrees = 0
  4. path = Path(__file__).parent / "../../input.txt"
  5.  
  6. with path.open() as f:
  7. line = f.readline()
  8. line = f.readline()
  9. line = line.replace("\n","")
  10. xLoc = 0
  11. while (line):
  12. xLoc = xLoc+3
  13. #determine if past end of input line, if yes, go back to beginning of line
  14. if (xLoc) > len(line)-1:
  15. xLoc = xLoc-len(line)
  16. #determine if tree in spot
  17. if (line[xLoc] == "#"):
  18. cntTrees += 1
  19. line = f.readline()
  20. line = line.replace("\n","")
  21.  
  22. print(cntTrees)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement