-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
57 lines (48 loc) · 1.42 KB
/
Copy pathtest.py
File metadata and controls
57 lines (48 loc) · 1.42 KB
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
import math, sys
#Generates successors for supplied value
def successors(val):
ret = []
if (val <= 200):
try:
ret.append([math.factorial(val), 1])
except:
pass
#Exception when values are not kosher I guess
try:
ret.append([math.floor(val), 2])
except:
ret.append([int(val), 2])
if (val 0 and queue[0][0] != goal:
current = queue.pop(0)
for x in successors(current[0]):
if not x[0] in seen:
queue.append(x)
seen[x[0]] = current
#For some reason, 12 doesn't work...
if (len(queue) == 0):
print "Failed to find steps..."
return None
#Converts the data structures to the series of steps that the algorithm found
print "Generating steps..."
done = False
steps = [queue[0]]
step = queue[0][0]
while not done:
if step != 4:
steps.append(seen[step])
step = seen[step][0]
else:
done = True
steps.reverse()
return steps
s = bfs(int(sys.argv[1]))
if not s == None:
for x in s:
if x[1] == None:
print "Start: " + str(x[0])
elif x[1] == 1:
print "Factorial: " + str(x[0])
elif x[1] == 2:
print "Floor: " + str(x[0])
elif x[1] == 3:
print "Square Root: " + str(x[0])