-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3.py
62 lines (45 loc) · 1.27 KB
/
day3.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
53
54
55
56
57
58
59
60
61
62
#only for Part 1 of day 3
#open file
forestFile=open(('/home/anjab/PycharmProjects/AdventofCode/venv/numbers.txt'), 'r')
forestList=forestFile.readlines()
treeCount=0
#skip first line
#second line: index 3 check which character, if #, treeCount+1
#next line: index 3+3 check which character
index=0
lineCount=0
for forestString in forestList:
for i in range(5):
forestString=forestString.rstrip('\r\n')+forestString.rstrip('\r\n')
#skip first line
if(index==0):
index=3
continue
try:
if(forestString[index]== '#'):
treeCount=treeCount+1
except:
break
index=index+3
lineCount=lineCount+1
if(lineCount==323):
break
print(treeCount)
#Part 2 of Day 3, to concerns slope Right 1, Down 2. For the other slopes, change the indexes in the above code snippet (line 21 and 29)
index=1
lineCount=0
for forestString in forestList:
lineCount=lineCount+1
if(lineCount<=2 or lineCount%2==0):
continue
for i in range(5):
forestString=forestString.rstrip('\r\n')+forestString.rstrip('\r\n')
try:
if(forestString[index]== '#'):
treeCount=treeCount+1
except:
break
index=index+1
if (lineCount == 323):
break
print(treeCount)