Sorting digits in a string or integer? : <p>I have a combination lock with 10 buttons and I have to press in 4 buttons and then hit Open. Order of the buttons doesn't matter and each button can only be pressed once.</p>

<p>I am sure there are some probability theory and permutation that makes this an easy problem, but I would like to solve it in Ruby.</p>

<p>My thought is to have a while loop and then sort the digits in the counter and if each digit only occur once, then try to insert it in a hash, where I than can get the length of the hash at the end to have number of combinations.</p>

<p>But how can I sort the digits in a string or inter?</p>

<p>Or is there a smarter algorithm for this?</p>
