Skip to main content
added 24 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATLAB, 33 bytes

@(n)(-1)^n*hypergeom([1 -n],[],1) 

UsesAnonympus function that uses the formula in Section 3 of Derangements and applications by Mehdi Hassani.

Example use:

>> @(n)(-1)^n*hypergeom([1 -n],[],1) ans = @(n)(-1)^n*hypergeom([1,-n],[],1) >> ans(6) ans = 265 

MATLAB, 33 bytes

@(n)(-1)^n*hypergeom([1 -n],[],1) 

Uses the formula in Section 3 of Derangements and applications by Mehdi Hassani.

Example use:

>> @(n)(-1)^n*hypergeom([1 -n],[],1) ans = @(n)(-1)^n*hypergeom([1,-n],[],1) >> ans(6) ans = 265 

MATLAB, 33 bytes

@(n)(-1)^n*hypergeom([1 -n],[],1) 

Anonympus function that uses the formula in Section 3 of Derangements and applications by Mehdi Hassani.

Example use:

>> @(n)(-1)^n*hypergeom([1 -n],[],1) ans = @(n)(-1)^n*hypergeom([1,-n],[],1) >> ans(6) ans = 265 
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

MATLAB, 33 bytes

@(n)(-1)^n*hypergeom([1 -n],[],1) 

Uses the formula in Section 3 of Derangements and applications by Mehdi Hassani.

Example use:

>> @(n)(-1)^n*hypergeom([1 -n],[],1) ans = @(n)(-1)^n*hypergeom([1,-n],[],1) >> ans(6) ans = 265