Genetic

From Esolang
Jump to navigation Jump to search

Genetic, as you could have guessed by its name, is an esolang that only uses the letters A, C, G, and T. The basic part is designed by User:iddi01.

It's designed to simulate genetic evolution though very simple rules.

Basic rules

Genetic programs modify themselves, with each letter executed in parallel. It can also be treated as "each turn, an empty new program is created, and with each letter executed, append it along with the modifications to the end of the new program". Each letter decides its behavior according to the previous letter, the letter and the next letter, which will be referred to in this article as geneL, geneM, and geneR:

Modifications

If a geneR is C, then the geneM Copies itself to the right, then the copy, wherever it's in the list C, A, G, T, becomes the next item, with wraparound (that is, a T would become C).
If a geneL is C, then the geneM becomes C;
If a geneM is C, and the geneR isn't G or empty, then the geneM deletes itself.

The only ways to increase the length of the genetics are having a C on the right edge, through a G which can Generate new letters, or via adjustments (see below).

Technically, anything except C is a no-op.

Adjustments

This section is still a work in progress. It may be changed in the future.

With only the basic rules, it produces pseudo-random genetics that looks "too random" to be an actual usable code, and in which C's and A's dominates. This can be fixed using adjustments. Since the current adjustments listed here are likely not the best set, this will remain a work-in-progress until a set of adjustments are proved to be better than all others (which is unlikely). Please contribute your own adjustment sets on the talk page!

The usual adjustment is basically when [geneL, geneM, geneR] is equal to [x, y, z], the geneM becomes <string>. A simple notation to describe the adjustment would be x,y,z,<string>.

The current best adjustment set is: (Feel free to edit this if you have a better one)

A,G,T,TC
A,A,A,GC

Using this adjustment set, The frequencies of the four letters tend to be reasonably equal, and the genetics tend to evolve into a random-but-ordered sequence, similarly to compiled programs and .pyc files. It is conjectured that if we run this set for a very long time, say a year, we might be able to create actual lifeforms!

Implementation

It's very easy to write an interpreter. Here's moderate one in Python, configured to the adjustment set above:

import copy
seq = input("Sequence: ").upper()                                                                                                                                           
li = ['C', 'A', 'G', 'T']
while True:
   newseq = ""
   for index in range(len(seq)):
       append = True
       copy = False
       if index > 0:
           if seq[index-1] == 'C':
               newseq += "" if seq[index] != 'G' else 'C'
               append = False
       if index < len(seq) - 1:
           if seq[index+1] == 'C':
               copy = True
           if index > 0:
               #adjustments goes here
               if seq[index-1] == 'A' and seq[index] == 'G' and seq[index+1] == 'T':
                   newseq += 'TC'
                   append = False
               elif seq[index-1] == seq[index] == seq[index+1] == 'A':
                   newseq += 'GC'
                   append = False
       if append: newseq += seq[index]
       if copy: newseq += li[(li.index(seq[index]) + 1) % 4]
           
   seq = newseq
   print(seq)
   if len(seq) > 172: print()

See also