From: "Peña, Botp" Date: 2008-09-05T10:47:08+09:00 Subject: Re: String Combine problem From: Richard Zenn [mailto:luckyzenn@gmail.com] # Here is an array s = ["aaa", "b", "c", "d", "ee", "f"] # I want to combine them with some rules # 1. # s[i].size > s[i+1].size # combine them # 2. # s[i+1].size > s[i].size # combine them rules 1 & 2 simply says that if they differ in size, combine them, no? # 3. # s[i].size + s[i+1].size where is the condition here? add the sizes?? it does not show in your output below # The upper result is # {"aaab"} # {"bc"} # {"bcd"} # {"cd"} # {"dee"} # {"eef"} hmmm, it seems that you are combining them regardless... ?? here is a simplistic code (judging only fr your output) botp@botp-desktop:~$ cat test.rb s = ["aaa", "b", "c", "d", "ee", "f"] t = [] (1..s.size-2).each do |i| t << s[i-1] + s[i] if s[i].size == s[i-1].size and s[i].size ==s[i+1].size t << s[i-1]+s[i]+s[i+1] end t << s[i] + s[i+1] end p t.uniq botp@botp-desktop:~$ ruby test.rb ["aaab", "bc", "bcd", "cd", "dee", "eef"] i hope that is ok to startup your ruby interest. next time, pls show your initial/tried code, no matter how wrong it is you think. help us help you, ie. kind regards -botp