On 25/11/05, cyberco removed_email_address@domain.invalid wrote:

```
puts str + c
```

Thoug ‘aaa’…‘zzz’ is certainly the most elegeant, maybe it would help

if you’d try to understand this recursion

def combinations(elements, length)

return [] if length == 0

return elements if length == 1

result = []

elements.each do | element |

combinations(elements, length - 1).each do | combination |

result << element + combination

end

end

result

end

# What you want

puts combinations((‘a’…‘c’).to_a, 3)

# Using the power of ducktyping

combinations([[1], [2], [3]], 3).each do | combination |

p combination

end

# What does this calculate?

combinations((1…3).to_a, 3).each do | combination |

p combination

end

cheers,

Brian

–

http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/