I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.42
sub units 0.00
+
0

Derangement Check

Verifies if a given permutation is a derangement.
Controller: CodeCogs

Interface

C++

Derangement Check

 
boolderangement_checkintn
int*a )[inline]
This function checks whether a given permutation, given as an array of numbers in the range \inline  1, 2, \ldots n, is a derangement. A derangement of the integers 1 through n is a permutation of the integers such that the first value is not 1, the second is not 2, and so on. In more formal terms, the following condition stands:

where \inline  \sigma is the given permutation.

Example:

#include <codecogs/maths/combinatorics/permutations/derangement_check.h>
#include <iostream>
int main()
{
  int x[4] = {4, 3, 2, 1}, y[5] = {1, 3, 2, 5, 4};
  std::cout << Maths::Combinatorics::Permutations::derangement_check(4, x) << std::endl;
  std::cout << Maths::Combinatorics::Permutations::derangement_check(4, y) << std::endl;
  return 0;
}

Output:

1
0

References:

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Parameters

nthe size of the permutation
athe actual permutation given as an array

Returns

true, if the permutation is a derangement, false otherwise

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.