Anyway, this blog post has tremendously helped me to get a firmer grasp of both the concept and implementation details. I particularly liked different examples ranging from simple to complex. I then implemented the fill algorithm trying my hardest not to look for hints.
Below are the fruits of my weekend fight with combinations:
def combinations(str)
return [str] if str.length == 1
combos = combinations(str[1..-1])
current = [str[0]]
combos.each {|combo| current += [str[0] + combo] }
return (current + combos)
end
No comments :
Post a Comment