Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file = open('Day3.txt')
- data = file.readlines()
- data = [x.strip() for x in data]
- #define the tree calculating method
- def count_trees(right, step, data):
- position = 0
- tree = 0
- for ind in range(0, len(data),step):
- line = data[ind]
- if len(line)-1 < position:
- line = line *(position//len(line) +1)
- if line[position] == '#':
- tree += 1
- position += right
- return tree
- #part 1
- count_trees(3,1,data)
- #part 2
- rights = [1,3,5,7,1]
- steps = [1,1,1,1,2]
- tree_found = 1
- for right, step in zip(rights, steps):
- tree = count_trees(right, step, data)
- tree_found *= tree
- tree_found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement