title: Optimizing Array Memory Usage
body: <p>I currently have a very large array of permutations, which is currently using a significant amount of RAM.  This is the current code I have which SHOULD:</p>
  
  <p>Count all but the occurrences where more than one '1' exists  or three '2's exist in a row.</p>
  
  <pre><code>arr = [*1..3].repeated_permutation(30).to_a;
  
  count = 0
  
  arr.each do |x|
      if not x.join('').include? '222' and x.count(1) &lt; 2
          count += 1
      end
  end
  
  print count
  </code></pre>
  
  <p>So basically this results in a 24,360 element array, each of which have 30 elements.</p>
  
  <p>I've tried to run it through Terminal but it literally ate through 14GB of RAM, and didn't move for 15 minutes, so I'm not sure whether the process froze while attempting to access more RAM or if it was still computing.  </p>
  
  <p>My question being: is there a faster way of doing this?</p>
  
  <p>Thanks!</p>