range result in Tuple! and how to convert into assocArray by sort?

rikki cattermole rikki at cattermole.co.nz
Tue May 10 03:38:08 UTC 2022


If I am understanding the problem correctly, this is a super expensive 
method for doing something pretty simple. Even if it is a bit more code, 
this won't require memory allocation which in this case wouldn't be 
cheap (given how big DNA tends to be).

string s = "ACGTACGT";

uint[4] counts;

foreach(char c; s) {
	switch(c) {
		case 'A':
		case 'a':
			counts[0]++;
			break;
		case 'C':
		case 'c':
			counts[1]++;
			break;
		case 'G':
		case 'g':
			counts[2]++;
			break;
		case 'T':
		case 't':
			counts[3]++;
			break;
		default:
			assert(0, "Unknown compound");
	}
}

writeln(counts);


More information about the Digitalmars-d-learn mailing list