-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scratch Work.py
153 lines (134 loc) · 3.93 KB
/
Scratch Work.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# num = 300
#
# adjacency_matrix = sumSquareList(num)
#
# adjList = []
#
# for key in adjacency_matrix:
# adjList.append(adjacency_matrix)
#
# graph = Graph(adjacency_matrix)
# print(graph)
# print(len(adjList))
# for k in range(1, num + 1): # To check if the Path is valid, checks every possible start
# flag = True
# path = (dfs_iterative(adjacency_matrix, k))
# for i in range(len(path) - 1):
# if not is_square(path[i] + path[i + 1]):
# flag = False
# # print(k, path)
# if flag:
# print(k)
# path18 = (dfs(adjList, 18))
# print(path18)
#
# for i in range(len(path18) - 1):
# print(path18[i], path18[i + 1], "SUM", path18[i] + path18[i + 1] )
# for k in range(25, 301):
# s = time.time()
# i = int(((math.floor(math.sqrt(k)) + 1) ** 2) / 2)
# j = random.randint(i, k)
# adjacency_matrix = sumSquareList(k)
# graph = Graph(adjacency_matrix)
# foundPath = False
# while i <= k and not foundPath:
# j = random.randint(i, k)
# while j <= k and not foundPath:
# # print(i, j, k)
# paths = (graph.find_all_paths(i, j))
# for item in paths:
# if legalSequence(item) and len(item) == k:
# # print("LEGAL", item)
# foundPath = True
# goodPath = item
# j += 1
# i += 1
# e = time.time()
# print(k, e - s, goodPath)
# adjacency_matrix = sumSquareList(45)
# for key in adjacency_matrix:
# print(key, adjacency_matrix[key])
# graph = Graph(adjacency_matrix)
#
# list = graph.findCompletePath(18, 32, 45)
#
# print(graph)
# adjacency_matrix = sumSquareList(15)
# g = Graph(adjacency_matrix)
# p = g.find_all_paths(8, 9)
# for item in p:
# print(item)
# k = 15
# for i in range(15, 30):
# adjacency_matrix = sumSquareList(i)
# graph = Graph(adjacency_matrix)
# legalPaths = []
# for j in range(1, i + 1):
# for k in range(1, i + 1):
# # print(j, k)
# paths = graph.find_all_paths(j, k)
# for item in paths:
# if len(item) == i:
# print(item)
# blank = input()
# for k in range(1, 200):
# adjMatrix = sumCubeList(k)
# # print(adjMatrix)
# g = Graph(adjMatrix)
# longestPath = []
# for i in range(1, k):
# for j in range(i, k):
# paths = g.find_all_paths(i, j)
# for item in paths:
# if len(item) >= len(longestPath):
# longestPath = item
# print(longestPath, "K", k, "Length", len(longestPath))
# for i in range(len(sumSequences[0])):
# if sumSequences[0][i] == sumSequences[1][i] and\
# sumSequences[1][i] == sumSequences[2][i] and\
# sumSequences[0][i] == sumSequences[2][i]:
# pass
# else:
# sumSequences[0][i], sumSequences[1][i], sumSequences[2][i] = "X", "X", "X"
#
# for item in sumSequences:
# print(item)
# class Stack:
# def __init__(self):
# self.items = []
#
# def isEmpty(self):
# return self.items == []
#
# def push(self, item):
# self.items.append(item)
#
# def pop(self):
# return self.items.pop()
#
# def peek(self):
# return self.items[len(self.items) - 1]
#
# def size(self):
# return len(self.item)
# class vertex(object):
# def __init__(self, k, adjacency):
# self.value = k
# self.adj = adjacency
# self.discover = False
#
# def discover(self):
# self.discover = True
# def dfs_iterative(graph, start): # Non-recursive DFS I found Online, still working on learning how to write my own
# stack, path = [start], []
#
# while stack:
# # print(stack)
# vertex = stack.pop()
# if vertex in path:
# continue
# path.append(vertex)
# for neighbor in graph[vertex]:
# stack.append(neighbor)
# print(path)
# return path