I have forgotten

• https://me.yahoo.com
COST (GBP)
0.42
0.00
0

# Derangement Check

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

C++

## Derangement Check

 boolderangement_check( int n int* a )[inline]
This function checks whether a given permutation, given as an array of numbers in the range $\inline&space;&space;1,&space;2,&space;\ldots&space;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:

$\sigma(i)&space;\neq&space;i,&space;\quad&space;\forall&space;i&space;=&space;\overline{1,&space;n}$

where $\inline&space;&space;\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

 n the size of the permutation a the 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.