Dear Jim Whittaker,

I just modified the method that I wrote in a previous answer.

I've put a ... return [] if str.size < 2
and a .. 1.upto(str.size-2) (instead of 0.upto(str.size-2))

... and I think it now meet your criterias.

def partitions(str)
  return [] if str.size < 2
  ary = [[str]]
  1.upto(str.size-2) do |first_slice_index| # don't recurse at the
last element (so size-2)
    first_slice  = str[0..first_slice_index]
    second_slice = str[(first_slice_index+1)..-1]
    other_slices = partitions(second_slice) # recursively
    other_slices.each do |slice|
      candidate = [first_slice] + slice
      ary.push candidate
    end
  end
  ary
end

1.upto(7) do |size|
  str = (1..size).map(&:to_s).join
  pts = partitions(str)
  puts "#{size} - #{pts.size} - #{pts}"
end

1 - 0 - []
2 - 1 - [["12"]]
3 - 1 - [["123"]]
4 - 2 - [["1234"], ["12", "34"]]
5 - 3 - [["12345"], ["12", "345"], ["123", "45"]]
6 - 5 - [["123456"], ["12", "3456"], ["12", "34", "56"], ["123",
"456"], ["1234", "56"]]
7 - 8 - [["1234567"], ["12", "34567"], ["12", "34", "567"], ["12",
"345", "67"], ["123", "4567"], ["123", "45", "67"], ["1234", "567"],
["12345", "67"]]
8 - 13 - [["12345678"], ["12", "345678"], ["12", "34", "5678"], ["12",
"34", "56", "78"], ["12", "345", "678"], ["12", "3456", "78"], ["123",
"45678"], ["123", "45", "678"], ["123", "456", "78"], ["1234",
"5678"], ["1234", "56", "78"], ["12345", "678"], ["123456", "78"]]

So... If this is the results you are expecting, let us know.

I agree with the others. It would be easier if you've had written a
simple test with the arguments and the expected results. But, you
still may do it!
I can help you to write a simple test so that somebody can come up
with a better approach than mine.

Best regards,
Abinoam Jr.

On Sat, Dec 21, 2013 at 9:00 PM, Hassan Schroeder
<hassan.schroeder / gmail.com> wrote:
> On Sat, Dec 21, 2013 at 1:29 PM, Jim Whittaker <lists / ruby-forum.com> wrote:
>
>> "habit of writing tests"
>
> see "Test Driven Development" (TDD) for a lot more info :-)
>
> --
> Hassan Schroeder ------------------------ hassan.schroeder / gmail.com
> http://about.me/hassanschroeder
> twitter: @hassan