views:

246

answers:

3

Let's give the GMO guys something to cry about:

Goal: Generate a sequence of DNA base pairs (A, T, G or C), 78 pairs long (not a big gene...), terminated by a newline, and print it.

Rules: The lines must be exactly 78 characters long with a terminating newline, and while the program can give the same result if invoked twice in a row, it cannot with necessity give two identical lines if the part of the program that does the work is doubled up.

Below is my own attempt in C (74 bytes):

int main(){int x=78;while(--x)putchar("\nATGC"[x?rand()%4+1:x]);return 0;}
+2  A: 

J: 19 chars

1!:2&2'AGCT'{~?78$4
cobbal
A: 

MATLAB 32 chars

x='ACGT';[x(randi(4,78,1)),'\n']

Since Matlab automatically adds a newline when it prints, one could reduce this to 25 chars like this:

x='ACGT';x(randi(4,78,1))
Jonas
A: 

Python (2.6) - 55 characters

import random;print''.join(random.sample('ATGC'*20,78))

I think this also satisfies the constraints of the problem :)

import random;random.choice("AT")*78
ChristopheD