Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
lisp
lingo
Commits
1a229b8e
Commit
1a229b8e
authored
Jul 06, 2017
by
Juergen Nickelsen
Browse files
lisp problem 26/99
parent
c43b20e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
regtests/099-lisp-problems.lisp
View file @
1a229b8e
...
...
@@ -442,16 +442,28 @@
;; ((A B C) (A B D) (A B E) ... )
(
defun
combination
(
n
l
)
(
let
((
len
(
length
l
))
acc
newlist
)
(
dotimes
(
i
(
-
len
(
1-
n
)))
(
let*
((
rest
(
nthcdr
i
l
))
((
resta
.
restd
)
rest
))
(
dolist
(
combi
(
combination
(
1-
n
)
restd
))
(
push
(
cons
resta
combi
)
acc
))))
acc
))
"Return all combinations of N elements of list L, leftmost first.
If N ist smaller than the length of L, return L."
(
let
((
len
(
length
l
)))
(
if
(
<=
len
n
)
(
list
l
)
(
if
(
zerop
n
)
(
list
nil
)
(
let
(((
first
.
rest
)
l
))
(
nconc
(
map
(
lambda
(
lrest
)
(
cons
first
lrest
))
(
combination
(
1-
n
)
rest
))
(
combination
n
rest
)))))))
(
test-is
"lisp problem 26/99"
(
combination
3
'
(
a
b
c
d
e
f
))
'
((
a
b
c
)
(
a
b
d
)
(
a
b
e
)
(
a
b
f
)
(
a
c
d
)
(
a
c
e
)
(
a
c
f
)
(
a
d
e
)
(
a
d
f
)
(
a
e
f
)
(
b
c
d
)
(
b
c
e
)
(
b
c
f
)
(
b
d
e
)
(
b
d
f
)
(
b
e
f
)
(
c
d
e
)
(
c
d
f
)
(
c
e
f
)
(
d
e
f
)))
(
done-testing
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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