Created
February 25, 2014 06:04
-
-
Save thomasballinger/9203583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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