Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 19:33
Show Gist options
  • Save anonymous/4331161 to your computer and use it in GitHub Desktop.
Save anonymous/4331161 to your computer and use it in GitHub Desktop.
Efficiently storing a deck of cards.
// Store a deck in a bit array by the following algorithm:
// value := pick[0];
// value = value * 51 + second pick
// value = value * 50 + third pick
// ..
// value = value * 1 + 52nd pick
// The first pick is pick[0]
BigInt StoreDeck(params int[] picks) {
BigInt value = pick[0];
for(int i = 1; i < picks.Length; i++) {
value *= (picks.Length - i) + 1;
value += picks[i];
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment