You have an equal number of cups and balls, each labelled from one to N. You randomly place one ball in each cup. Determine the number of possible combinations such that no balls are in the cup with a matching number. For example, if you have three balls and three cups, there are two valid solutions:
The following permutations do not meet the criteria for the reasons listed:
Good luck!
I think that with this kind of problem, you can process in two steps.
A first easy problem with small N (to test perms for example). And a harder problem with big N, which
oblige to find another algorithm.
http://oeis.org/A000166
Back to basics 16 - byte order
149 Solvers
Back to basics 18 - justification
150 Solvers
Find out missing number from a vector of 9 elements
207 Solvers
100 Solvers
37 Solvers