## Copyright (C) 2018 Dildar
## 
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see
## <https://www.gnu.org/licenses/>.

## -*- texinfo -*- 
## @deftypefn {} {@var{ret} =} npermutek (@var{n}, @var{k})
##
## @seealso{}
## @end deftypefn

## Author: Dildar <dildarsk101010@gmail.com>
## Created: 2018-03-13

function ret = npermutek (n, k)
    if (nargin != 2
      || ! (isreal (k) && isscalar (k))
      || ! (isnumeric (n) && isvector (n)))
    print_usage ();
  endif
  if (k < 0 || k != fix (k))
    error ("npermutek: k must be an integer >= 0");
  elseif (isscalar (n) && (iscomplex (n) || n < k || n < 0 || n != fix (n)))
    error ("npermutek: n must be a non-negative integer >= k");
  endif
    ret = round (prod (n-k+1:n));
endfunction


%!test assert (1+eps, 1, 2*eps)
%!test assert (100+100*eps, 100, -2*eps)
%!test assert (isempty ([]))
%!test assert ([1, 2; 3, 4] > 0)