]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day03/count_trees.py
Day 14 - implemented in bash, because, well, I could
[advent-of-code-2020.git] / day03 / count_trees.py
1 #!/usr/bin/python3
2
3 trees_count = 0
4 position = 3 # forth square in, we moved 3 right from where we were, 0 + 3 -> 3
5 on_first_line = True
6 line_number = 0
7
8 for line in open("input.txt", "r"):
9     line_number += 1
10     print("line: ", line_number)
11     line = line.rstrip()
12     print(line)
13     if on_first_line:
14         on_first_line = False
15         continue
16     print(line[position], position)
17     if line[position] == "#":
18         trees_count += 1
19         print("hit tree")
20     else:
21         print("missed tree")
22     # now add 3 to the position
23     position += 3
24     if position >= len(line):
25         position = position - len(line)
26
27 print("There were", trees_count, "trees")