mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-14 14:43:34 +02:00
2020 - Day 3
This commit is contained in:
29
2020/day3_2.py
Normal file
29
2020/day3_2.py
Normal file
@@ -0,0 +1,29 @@
|
||||
input = []
|
||||
with open('day3_input.txt', 'r') as f:
|
||||
for line in f.readlines():
|
||||
input.append(line.strip())
|
||||
|
||||
|
||||
|
||||
def slide(forest, pos, slope):
|
||||
if pos[1]+slope[1] >= len(forest):
|
||||
return 0
|
||||
else:
|
||||
pos[0] += slope[0]
|
||||
pos[1] += slope[1]
|
||||
row = forest[pos[1]]
|
||||
if row[pos[0]%len(row)] == '#':
|
||||
return 1 + slide(forest, pos, slope)
|
||||
else:
|
||||
return slide(forest, pos, slope)
|
||||
|
||||
|
||||
start = (0, 0)
|
||||
slopes = [(1,1), (3, 1), (5,1), (7,1), (1,2)]
|
||||
|
||||
result = 1
|
||||
for slope in slopes:
|
||||
trees = slide(input, list(start), slope)
|
||||
print(slope, trees)
|
||||
result *= trees
|
||||
print(result)
|
||||
Reference in New Issue
Block a user