ruby - how to group string elements for a desired length -
i want create subsets of string dataset. example, have 150 words in different lengths. need distribute them groups have max length of 100 charachter. couldn't find way of doing in optimal way. case minimum number of new groups.
since not familiar general format of stack sorry complicated question.
websites array sample of data, complete 1 contains more websites. trying putting these websites new arrays have 255 length limit. , trying in efficient way, creating minimum number of new arrays.
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]
this code wrote far, yet doesn't need exactly.
while total <= 255 puts total total += websiteslength[y] total += 1 if total <= 255 y += 1 else total -= a[y] y += 1 total += a[y] if total == 255 #total has reached 255 start new sub-array else total -= a[y] y += 1 total += a[y] if total == 255 #total has reached 255 start new sub-array else total -= a[y] y += 1 total += a[y] end end end end
Comments
Post a Comment