Quote:
Originally posted by kev82
my method bounds the elements(to the maximium value of an int) i just thought that a bound of 9 was quite low, and i couldnt see an easy way to modify it(but i dont know python) your algorithm is much simpler than mine and probably better at low vales of n and k but i like to solve the problem in general not just in a few cases which is why i made the comment.
|
Well, really mine is a general solution as well if you abstract away the 0-9 assumption. The general solution I suggest is just: create all the combinations and just iterate through them, eliminating invalid ones. Of course, for things that use the 0-9 assumption creating the range is eased by the functionality offered by some languages (like Python) in that they will create the list for you. But if you have to create the list yourself, you can still do the same thing, only it makes sense to cull up front instead of after the list is done.