-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3part2.py
104 lines (93 loc) · 2.91 KB
/
day3part2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
def split_into_list(file_path):
f = open(file_path, "r")
list_of_lists = []
for line in f:
stripped_line = line.strip()
stripped_line = str(stripped_line)
line_list = stripped_line.split()
list_of_lists.append(stripped_line)
f.close()
return(list_of_lists)
def multiply_each_line(list_of_lists, filepath2):
f = open(filepath2, "w")
for i in list_of_lists:
f.write(i*75) # Just an arbitrary number so I could make sure it wouldn't hit the wall
#f.write("\n")
f.close()
def string_to_list_of_chars(string):
return [char for char in string]
def find_trees_and_opens(list_of_chars):
newlist = []
for i in list_of_chars:
if i == "#":
newlist.append("Tree")
elif i == ".":
newlist.append("Open")
else:
print("An error occured. Sorry.")
quit()
return newlist
def three_right_one_down(list_of_trees_opens):
newlist = []
k = 0
for i in list_of_trees_opens:
try:
newlist.append(list_of_trees_opens[k])
k = k+2325
k = k+3
except:
return newlist
def one_right_one_down(list_of_trees_opens):
newlist = []
k = 0
for i in list_of_trees_opens:
try:
newlist.append(list_of_trees_opens[k])
k = k+2325
k = k+1
except:
return newlist
def five_right_one_down(list_of_trees_opens):
newlist = []
k = 0
for i in list_of_trees_opens:
try:
newlist.append(list_of_trees_opens[k])
k = k+2325
k = k+5
except:
return newlist
def seven_right_one_down(list_of_trees_opens):
newlist = []
k = 0
for i in list_of_trees_opens:
try:
newlist.append(list_of_trees_opens[k])
k = k+2325
k = k+7
except:
return newlist
def one_right_two_down(list_of_trees_opens):
newlist = []
k = 0
for i in list_of_trees_opens:
try:
newlist.append(list_of_trees_opens[k])
k = k+4650
k = k+1
except:
return newlist
list_of_lists = split_into_list("day3input.txt")
multiply_each_line(list_of_lists, "day3inputmultipliedpart2.txt")
list_of_lists = split_into_list("day3inputmultipliedpart2.txt")
list_as_string = "".join(list_of_lists)
list_of_chars = string_to_list_of_chars(list_as_string)
list_of_trees_opens = find_trees_and_opens(list_of_chars)
three_one = three_right_one_down(list_of_trees_opens)
one_one = one_right_one_down(list_of_trees_opens)
five_one = five_right_one_down(list_of_trees_opens)
seven_one = seven_right_one_down(list_of_trees_opens)
one_two = one_right_two_down(list_of_trees_opens)
mult_trees = three_one.count("Tree") * one_one.count("Tree") * five_one.count("Tree") * seven_one.count("Tree") * one_two.count("Tree")
print(one_two)
print(mult_trees)