Question
Even only 52 cards, the permutationIndex
where I describe in Explanations section, would be a huge number; it is
If I've understood you right, the following code implements this:
public class Dealer {
public int Dealing() {
var number=
_freeCards.Count>0
?_freeCards.Dequeue()
:_lastNumber++;
_dealtCards.Add(number);
return number;
}
public void Collect(int number) {
if(!_dealtCards.Remove(number))
throw new ArgumentException("Card is not in use", "number");
_freeCards.Enqueue(number);
}
readonly HashSet _dealtCards=new HashSet();
readonly Queue _freeCards=new Queue(); // "Pool" of free cards.
int _lastNumber;
}