Day 3
This commit is contained in:
63
2020/03/03.py
Executable file
63
2020/03/03.py
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Advent Of Code 2020 - Day 3
|
||||
|
||||
"""
|
||||
...#.#..#..#..#..............##
|
||||
.##.......###.#......#....#..##
|
||||
..##.##.#......#....#..#...#..#
|
||||
|
||||
|
||||
..##.......
|
||||
"""
|
||||
|
||||
filename = "input.txt"
|
||||
|
||||
with open(filename) as f:
|
||||
content = f.readlines()
|
||||
|
||||
trees = 0
|
||||
|
||||
totalRows = len(content)-1
|
||||
totalColumns = len(content[0])-1
|
||||
|
||||
#print (totalColumns)
|
||||
#print (totalRows)
|
||||
|
||||
|
||||
x,y = 0,0
|
||||
moveRight = 3
|
||||
moveDown = 1
|
||||
|
||||
row = 0
|
||||
|
||||
while row < totalRows:
|
||||
|
||||
x = x + moveDown
|
||||
y = y + moveRight
|
||||
|
||||
|
||||
if y >= totalColumns:
|
||||
y = y - totalColumns
|
||||
# print (y)
|
||||
|
||||
# print (x, y)
|
||||
if content[x][y] == "#":
|
||||
trees = trees + 1
|
||||
|
||||
row = row +1
|
||||
|
||||
print (trees)
|
||||
|
||||
"""
|
||||
0,0
|
||||
right 3, down 1
|
||||
+3,+1
|
||||
|
||||
check if y is >= len(content)
|
||||
print trees result
|
||||
|
||||
check if x is >= len(line)
|
||||
move to start of the line and continue
|
||||
|
||||
"""
|
Reference in New Issue
Block a user