-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3-1.py
52 lines (45 loc) · 997 Bytes
/
day3-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
seq = []
xInc = 3
yInc = 1
msgTest = "Trying position (%d,%d)..."
msgPass = "space"
msgFail = "tree"
msgResult = "You hit %d trees."
testseq = [
"..##.......",
"#...#...#..",
".#....#..#.",
"..#.#...#.#",
".#...##..#.",
"..#.##.....",
".#.#.#....#",
".#........#",
"#.##...#...",
"#...##....#",
".#..#...#.#"
]
def readInput(file, list):
file = open(file, "r")
for line in file.readlines():
seq.append(line.rstrip())
def checkForTrees(seq, xInc, yInc):
x = 0
y = 0
trees = 0
for y in range(len(seq)):
x += xInc
y += yInc
if x >= len(seq[0]):
x = x - len(seq[0])
if y >= len(seq):
return trees
print(msgTest % (x, y))
if seq[y][x] == "#":
print(msgFail)
trees += 1
else:
print(msgPass)
return None
readInput("day3-input.txt", seq)
trees = checkForTrees(seq, xInc, yInc)
print(msgResult % trees)