title: how to group string elements for a desired length
body: <p>I want to create subsets of a string dataset. For example, I have 150 words in different lengths. I need to distribute them to the groups which have max length of 100 charachter. I couldn't find any way of doing this in optimal way. For this case minimum number of new groups.</p>
  
  <p>Since I am not familiar with general format of stack sorry for complicated question. </p>
  
  <p>Websites array is a sample of my data, complete one just contains more websites. What I am trying to do is putting these websites to new arrays which have 255 length limit. And I am trying to do is in most efficient way, by creating minimum number of new arrays.</p>
  
  <pre><code>websites=["0n-line.tv","100dollars-seo.com","12masterov.com","1pamm.ru","4webmasters.org","5forex.ru","7makemoneyonline.com","acads.net"]
  
  websiteslength =[10, 18, 14, 8, 15, 9, 20, 9, 10, 11]
  </code></pre>
  
  <p>This is the code I wrote so far, yet it doesn't do what I need exactly.</p>
  
  <pre><code>while total &lt;= 255
    puts total
    total += websiteslength[y]
    total += 1
    if total &lt;= 255
      y += 1
    else
      total -= a[y]
      y += 1
      total += a[y]
      if total == 255
        #total has reached to 255 start new sub-array
      else
        total -= a[y]
        y += 1
        total += a[y]
        if total == 255 
        #total has reached to 255 start new sub-array
        else
        total -= a[y]
        y += 1
        total += a[y]
        end
      end
    end
  end
  </code></pre>