Skip to content

Commit

Permalink
subfactorial(n,k): return 0 when k > n and n >= 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
trizen committed Jul 23, 2021
1 parent e1d0319 commit 18cac8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8224,7 +8224,7 @@ package Sidef::Types::Number::Number {

return ZERO if ($k < 0);
return ONE if ($n == 0);
goto &nan if ($n < 0);
return ZERO if ($n < 0);

my $z = Math::GMPz::Rmpz_init();

Expand Down
14 changes: 10 additions & 4 deletions lib/Sidef/Types/Number/Number.pod
Original file line number Diff line number Diff line change
Expand Up @@ -5893,7 +5893,7 @@ Returns the n-th semiprime number.

Example:

say 10.of {|k| nth_semiprime(10**k) }
say 10.of {|k| semiprime(10**k) } #=> OEIS: A114125

Aliases: I<nth_semiprime>

Expand Down Expand Up @@ -6015,7 +6015,7 @@ Example:

solve_pell(d, k=1)

Find the smallest pair of integer solutions C<(x,y)> to the Pell equation: C<x^2 - d*y^2 = k>.
Find the smallest pair of integers C<(x,y)> that satisfy the Pell equation: C<x^2 - d*y^2 = k>.

Example:

Expand Down Expand Up @@ -6405,7 +6405,12 @@ Stirling numbers of the third kind (also known as Lah numbers).

subfactorial(n,k=0)

Number of derangements of a set with n elements with k fixed points. Also known as the rencontres numbers.
Number of derangements of a set with n elements having exactly k fixed points. Also known as the rencontres numbers.

Example:

say 20.of { .subfactorial } #=> A000166
say 20.of { .subfactorial(2) } #=> A000387

=cut

Expand All @@ -6425,6 +6430,7 @@ Example:

n.subsets
n.subsets(k)
n.subsets { ... }
n.subsets(k, { ... })

Returns an array with the subsets of the integers in the range C<0..n-1>, or iterates over the k-subsets when a block is given.
Expand All @@ -6434,7 +6440,7 @@ Example:
say 5.subsets # all k-subsets of 0..4
say 5.subsets(2) # all 2-subsets of 0..4

5.subsets({|*a| say a }) # iterate over all k-subsets of 0..4
5.subsets {|*a| say a } # iterate over all k-subsets of 0..4
5.subsets(2, {|*a| say a }) # iterate over all 2-subsets of 0..4

=cut
Expand Down

0 comments on commit 18cac8b

Please sign in to comment.