Last active
December 15, 2019 22:35
-
-
Save rtobar/ab99f05e89211c812e4fa9c6f4f98dcd 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
from collections import Counter | |
import string | |
import sys | |
def factores_primos(n): | |
factor = 2 | |
while n >= 2: | |
if n % factor: | |
factor += 1 | |
else: | |
n //= factor | |
yield factor | |
numeros = [int(line.strip()) for line in sys.stdin.readlines()] | |
factorizaciones = [sorted(Counter(factores_primos(numero)).items()) for numero in numeros] | |
palabras = [''.join(string.ascii_lowercase[potencia - 1] for _primo, potencia in factorizacion) | |
for factorizacion in factorizaciones] | |
print(palabras) | |
# $> python primes_crypto.py < ciphers.txt | |
# ['turing', 'dijstra', 'programa', 'desafio', 'algoritmo'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment