-
-
Save dandevac/a514312219d4e775b59b18edf25b9d87 to your computer and use it in GitHub Desktop.
self-mutating quine
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 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