Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created February 25, 2014 06:04
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 thomasballinger/9203583 to your computer and use it in GitHub Desktop.
Save thomasballinger/9203583 to your computer and use it in GitHub Desktop.
import itertools
def brute():
for candidate in itertools.permutations(range(8)):
if (len(set(x - y for x, y in enumerate(candidate))) == 8 and
len(set(x + y for x, y in enumerate(candidate))) == 8):
yield candidate
def ordinals():
opposite_of_teenager = ["th", "st", "nd", "rd"] + ["th"] * 6
gen = ("%d%s" % d for d
in itertools.izip(itertools.count(),
itertools.chain(opposite_of_teenager,
["th"] * 10,
itertools.cycle(opposite_of_teenager))))
gen.next() # drop one for one-based indexing
return gen
for i, x in itertools.izip(ordinals(), brute()):
print "%s solution:%r" % (i, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment