Created
May 28, 2021 22:35
-
-
Save franps/fb9db844c9e25a3a7ba3a71468fc7a0a 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 random | |
import math | |
# Randomizo una palabra y me fijo si es igual a la segunda, hay n! combinaciones posibles | |
# puede que el shuffle repita combinaciones, pero bueno, rock and roll | |
def randograma (p1,p2): | |
p1 = p1.lower().replace(' ','') | |
p2 = p2.lower().replace(' ','') | |
for i in range(math.factorial(len(p1))): # O(N!) | |
shuffled = ''.join(random.sample(p1, len(p1))) | |
if shuffled == p2: | |
return True | |
print ("O no son anagramas o tuviste muy poca suerte pibe") | |
return False | |
print(randograma('samYmasitas','masItassamy')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment