-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18. max path.py
80 lines (65 loc) · 1.63 KB
/
18. max path.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
def max_path():
maxpath = open("maxpathtext.txt")
maxpath_array = [x.strip('\n') for x in maxpath.readlines()]
maxpathsplit = []
global maxpathints
maxpathints = []
global paths
paths = []
for i in maxpath_array:
maxpathsplit.append(i.split(' '))
for i in maxpathsplit:
i = list(map(int,i))
maxpathints.append(i)
#print(i)
return maxpathints
def binary():
x = 2**14
print(bin(x))
y = []
for i in range(x):
z = bin(x-i)
y.append(z)
global new_y
new_y = []
for i in range(len(y)):
j = y[i][2:]
j = j.zfill(14)
new_y.append(j)
return new_y
# def adjacent(i,j):
# # take in coords of maxpathints
# x = maxpathints[i+1][j], maxpathints[i+1][j+1]
# if x[0] > x[1]:
# y = x[0]
# else:
# y = x[1]
# j = j+1
# i = i+1
# paths.append(y)
# print(i,j)
# try:
# adjacent(i,j)
# except:
# IndexError
#outputs coords of adjacent on next line
# i-->i+1
#j-->j & j+1
#find which is bigger, append to path
max_path()
binary()
print(len(new_y))
def summing():
for i in range(len(new_y)):
x = 0
path = []
for j in range(len(maxpathints)):
path.append(maxpathints[j][x])
x = x + int(new_y[i][-j])
paths.append(sum(path))
summing()
print(new_y[0])
print(max(paths))
#make some ticker for x coord within loop over binaries
# add new_y[-i] to ticker
#append maxpathints