Skip to content

Instantly share code, notes, and snippets.

@ackjake
Created December 7, 2012 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ackjake/4233224 to your computer and use it in GitHub Desktop.
Save ackjake/4233224 to your computer and use it in GitHub Desktop.
static bool CheckBad(int[] a)
{
for (int i = 0; i < a.Length; i++)
if (a[i] != i)
return false;
return true;
}
if (N >= 2)
{
int[] nums = new int[N];
for (int i = 0; i < N; i++)
{
nums[i] = i;
}
do
{
Shuffle(nums);
} while (CheckBad(nums));
if (true)
{
for (int i = 0; i < nums.Length; i++)
{
Console.WriteLine("Person #" + (i + 1) + " should buy a gift for Person #" + (nums[i] + 1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment