Compute all of the permutations of the input list and then filter out the ones that have an element in the same position as the input list. If you need more detail, leave a comment.
Edit 1:
Define (or maybe it's defined already? Good exercise, anyway) a procedure called filter
that takes as its first argument a procedure p
and a list l
as its second argument. Return a list containing only the values for which (p l)
returns a truthy value.
Define a procedure derangement?
that tests if a list l1
is a derangement of l2
. This will be handy when paired with filter
.