Skip to content

Instantly share code, notes, and snippets.

@dandevac
Created July 11, 2017 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dandevac/a514312219d4e775b59b18edf25b9d87 to your computer and use it in GitHub Desktop.
Save dandevac/a514312219d4e775b59b18edf25b9d87 to your computer and use it in GitHub Desktop.
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