Last active
August 9, 2017 20:35
-
-
Save heshamnaim/85b77d1708146343175cd5486de53893 to your computer and use it in GitHub Desktop.
Prancing Pony
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
from itertools import permutations,combinations | |
import time | |
start_time = time.time() | |
def palindrome_combinations(dwarf_names): | |
start_time = time.time() | |
for i in xrange(0,len(dwarf_names)): | |
for j in list(combinations(dwarf_names,i+1)): | |
for k in list(permutations(j)): | |
combination = "".join(k).lower() | |
if str(combination) == str(combination)[::-1]: | |
yield combination | |
print("Running time is %s seconds" % (time.time() - start_time)) | |
print list(palindrome_combinations(["Gimli", "Fili","Ilif","Ilmig","Mark"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment