Tuesday, July 5, 2011

Iterative algorithm for generating permutations from sets' single elements

My friend asked on facebook for a iterative algorihm that would generate all possible strings from given sets in a way that for ex. given {a,b,c}, {d,e}, {f} should produce {adf, aef, bdf, bef, cdf, cef}.



There is still a recursive call moved to bump_next method. I'm trying to get rid of that one and make it fully iterative.
That was much fun doing it, as it has some tricky parts. Probably faster algorithm for that already exists, but I couldn't find any. Lots of fun.

No comments:

Post a Comment