better (and faster) solution
This commit is contained in:
parent
fcd394aaba
commit
a3d2b5140f
16
day03.py
Normal file → Executable file
16
day03.py
Normal file → Executable file
@ -8,19 +8,13 @@ def check_for_trees(right_step, down_step, treelines):
|
|||||||
x = 0
|
x = 0
|
||||||
y = 0
|
y = 0
|
||||||
tree_count = 0
|
tree_count = 0
|
||||||
for treeline in treelines:
|
maxX = len(treelines[0])
|
||||||
if y % down_step != 0:
|
while y < len(treelines):
|
||||||
y = y + 1
|
if treelines[y][x] == '#':
|
||||||
continue
|
|
||||||
|
|
||||||
while len(treeline) < x + 1:
|
|
||||||
treeline = treeline + treeline
|
|
||||||
|
|
||||||
if treeline[x] == '#':
|
|
||||||
tree_count = tree_count + 1
|
tree_count = tree_count + 1
|
||||||
|
|
||||||
x = x + right_step
|
y = y + down_step
|
||||||
y = y + 1
|
x = (x + right_step) % maxX
|
||||||
|
|
||||||
return tree_count
|
return tree_count
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user