N = 100
print "N:",N

connected = [[]]
for i in range(N):
	connected.append([])
for m in range(1,N+1):
	for n in range(N,0,-1):
		if ((not m == n) and (m%n == 0 or n%m == 0)):
			connected[m].append(n)

def explore(path):
	global longestLength, longestPath, connected

	isExtendable = 0
	n = path[-1]
	for m in connected[n]:
		if not m in path:
			isExtendable = 1
			newPath = list(path)
			newPath.append(m)
			explore(newPath)
	if not isExtendable:
		if len(path) > longestLength:
			longestLength = len(path)
			longestPath = path
			print longestLength,longestPath

longestPath = []
longestLength = 0

explore([81])

@@ -1,8 +1,190 @@
+# For fivethirtyeight.com Riddler. Search for longest path in divisor graph.%0D%0A# This produces a path of length 74 in a few seconds when run with pypy.%0D%0A%0D%0Afrom random import shuffle%0D%0A
 N = 100%0D
@@ -389,16 +389,133 @@
 d(n)%0D%0A%0D%0A
+# Prioritize well-connected neighbors%0D%0Afor n in range(1,N+1):%0D%0A%09connected%5Bn%5D.sort(key=lambda x:len(connected%5Bx%5D))%0D%0A%0D%0A
 def expl
@@ -943,10 +943,62 @@
 re(%5B
-81
+92%5D)%0D%0Afor n in range(100,1,-1):%0D%0A%09print n%0D%0A%09explore(%5Bn
 %5D)%0D%0A

Update NumberPath.py