Skip to content

Instantly share code, notes, and snippets.

@jashsu
Last active February 7, 2017 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashsu/3f5eaf0398f49c8fa68431febde78847 to your computer and use it in GitHub Desktop.
Save jashsu/3f5eaf0398f49c8fa68431febde78847 to your computer and use it in GitHub Desktop.
>>> def findchildren(chain, tail, used):
for move in bogmoves:
newtail = tuple(map(operator.add, tail, move))
if newtail[0] > -1 and newtail[0] < bogsize and\
newtail[1] > -1 and newtail[1] < bogsize and\
newtail not in used:
#sys.stdout.write(">")
#if using isValid() then insert check here
bogchains.append(findchildren(chain + bogboard[newtail[0]][newtail[1]], newtail, used + [newtail]))
#sys.stdout.write("<")
return chain
>>> def generatelist():
for x in xrange(bogsize):
for y in xrange(bogsize):
head = (x,y)
print head
bogchains.append(findchildren(bogboard[x][y],head,[head]))
#print "\n" + str(bogchains)
>>> bogboard = [['a','t','e','e'],['a','p','y','o'],['t','i','n','u'],['e','d','s','e']]
>>> bogsize = 4
>>> bogmoves = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
>>> generatelist()
(0, 0)
(0, 1)
(0, 2)
(0, 3)
(1, 0)
(1, 1)
(1, 2)
(1, 3)
(2, 0)
(2, 1)
(2, 2)
(2, 3)
(3, 0)
(3, 1)
(3, 2)
(3, 3)
>>> len(bogchains)
12029704
>>> 'tepee' in bogchains
False
>>> 'pins' in bogchains
True
>>> 'pines' in bogchains
True
>>> 'dates' in bogchains
False
>>> 'pint' in bogchains
False
>>> 'sid' in bogchains
True
>>>
@jashsu
Copy link
Author

jashsu commented Feb 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment