Skip to content

Instantly share code, notes, and snippets.

@franps
Created May 28, 2021 22:35
Show Gist options
  • Save franps/fb9db844c9e25a3a7ba3a71468fc7a0a to your computer and use it in GitHub Desktop.
Save franps/fb9db844c9e25a3a7ba3a71468fc7a0a to your computer and use it in GitHub Desktop.
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