Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Knut Olav Bøhmer
alexandria
Commits
0e6be926
Commit
0e6be926
authored
Oct 30, 2011
by
Mason Smith
Committed by
Nikodemus Siivola
Oct 30, 2011
Browse files
improved -- well, fixed -- SUBFACTORIAL
Plus tests.
parent
75f9136a
Changes
2
Hide whitespace changes
Inline
Side-by-side
numbers.lisp
View file @
0e6be926
...
...
@@ -227,11 +227,12 @@ greater then K."
(
defun
subfactorial
(
n
)
"Subfactorial of the non-negative integer N."
(
check-type
n
(
integer
0
))
(
case
n
(
0
1
)
(
1
0
)
(
otherwise
(
floor
(
/
(
+
1
(
factorial
n
))
(
exp
1
))))))
(
if
(
zerop
n
)
1
(
do
((
x
1
(
1+
x
))
(
a
0
(
*
x
(
+
a
b
)))
(
b
1
a
))
((
=
n
x
)
a
))))
(
defun
count-permutations
(
n
&optional
(
k
n
))
"Number of K element permutations for a sequence of N objects.
...
...
tests.lisp
View file @
0e6be926
...
...
@@ -991,6 +991,31 @@
(
list
p
xv
))
(
2
#(
10
2
10
)))
(
deftest
subfactorial.1
(
mapcar
#'
subfactorial
(
iota
22
))
(
1
0
1
2
9
44
265
1854
14833
133496
1334961
14684570
176214841
2290792932
32071101049
481066515734
7697064251745
130850092279664
2355301661033953
44750731559645106
895014631192902121
18795307255050944540
))
;;;; Arrays
#+
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment