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

MichaelBi shunjie.bi at gmail.com
Tue May 10 05:09:39 UTC 2022


On Tuesday, 10 May 2022 at 03:38:08 UTC, rikki cattermole wrote:
> 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);

yes, thanks. understood this. the problem for me now is after 
learning D, always thinking about using range and function 
composition...and forgot the basic algorithm :)


More information about the Digitalmars-d-learn mailing list