Skip to content

Instantly share code, notes, and snippets.

@dandevac

dandevac/quine.py Secret

Created Jul 11, 2017
Embed
What would you like to do?
self-mutating quine
import random
import itertools
def main():
def_len = 4
nucleotyde_set = [''.join(i) for i in itertools.combinations_with_replacement('ACGT', 3)]
nucleotyde_chain = [random.choice(nucleotyde_set) for i in range(def_len)]
random.seed(hash(''.join(nucleotyde_chain)))
if random.randint(0, 10) % 2 == 0:
del nucleotyde_chain[random.randint(0, len(nucleotyde_chain) - 1)]
else:
nucleotyde_chain.append(nucleotyde_set[random.randint(0, len(nucleotyde_set) - 1)])
source = ["import random", "import itertools", "\n", "def main():", " def_len = 4", " nucleotyde_set = [''.join(i) for i in itertools.combinations_with_replacement('ACGT', 3)]", " nucleotyde_chain = %s", " random.seed(hash(''.join(nucleotyde_chain)))", " if random.randint(0, 10) % 2 == 0:", " del nucleotyde_chain[random.randint(0, len(nucleotyde_chain) - 1)]", " else:", " nucleotyde_chain.append(nucleotyde_set[random.randint(0, len(nucleotyde_set) - 1)])", " source = %s", " for i in range(0, 6):", " print(source[i])", " print(source[6] % nucleotyde_chain)", " for i in range(7, 12):", " print(source[i])", " print(source[12] % source)", " for i in range(13, len(source)):", " print(source[i])", "\n", "if __name__ == '__main__':", " main()"]
for i in range(0, 6):
print(source[i])
print(source[6] % nucleotyde_chain)
for i in range(7, 12):
print(source[i])
print(source[12] % source)
for i in range(13, len(source)):
print(source[i])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.