title: How do I store 262144 varibles efficiently? Multi-dimensional array?
body: <p>I'm trying to write a program that reads a .txt file containing several thousand strings (each one is exactly 9 letters long) made up only of the letters A,C,G and T (i.e. DNA sequences).</p>
  
  <p>Now, there are of course 4^9 possible combinations of A,C,G and T in a 9-letter string. I need to know how often each of these 262144 combinations appears in my .txt file.</p>
  
  <p>My problem is that I (obviously) don't want to initialize 262144 individual variables, increment each when a match is found and then print them all individually, because that would be crazy.</p>
  
  <p>So, my idea was to create either some kind of tree which goes down the branches according to the letter encountered at each node and stores the number of times each branch was 'run down' (i.e. each possible 9-letter combination) at the last node.</p>
  
  <p>Or an array of 262144 positions where I can store the number of appearances of each possible combination. For that, however, I would need some kind of non-redundant system that chooses a unique position in the array (to store the number of times that combination has been encountered) based on which letters have been encountered in which sequence in the 9-letter string.</p>
  
  <p>For example: For each 'A' encountered in the 9-letter string, I increment my 'pointer variable' (which points to the position in the big array) by 0, so every time the sequence AAAAAAAAA is encountered, position [0] of my array is incremented by 1. For every 'T' I increment the pointer by 1, so TTTTTTTTT would increment position [9] of my array by 1 and so on.</p>
  
  <p>This, however, gives me the problem that both sequences AAAAAAAAT and TAAAAAAAA (and all other combinations of 8 As and 1T) will increment position [1] of the array. So I would have to use some kind of system where the pointer can actually reach each value between 0 and 262143 exactly once?</p>
  
  <p>I'm sure there is some better way? Multi-dimensional arrays or something like that?</p>
  
  <p>Best regards,
  rokyo</p>