fork download
  1. :- use_module(library(clpfd)).
  2.  
  3. permut(L,N) :-
  4. length(L, N),
  5. L ins 1..N,
  6. all_different(L),
  7. label(L).
  8.  
  9. noFixpoint([],_Xs).
  10. noFixpoint([X|Xs],N1) :-
  11. X #\= N,
  12. N1 #= N-1,
  13. noFixpoint(Xs,N).
  14.  
  15. derangement(L,N) :-
  16. permut(L,N),
  17. noFixpoint(L,0).
  18.  
  19. findDerangements(N,Ls) :-
  20. findall(L,derangement(L,N),Ls).
  21.  
  22. :- findDerangements(6,Ls), length(Ls,N), print(Ls), nl, print(N).
Success #stdin #stdout #stderr 0.32s 8372KB
stdin
Standard input is empty
stdout
[[2,1,4,3,6,5],[2,1,4,5,6,3],[2,1,4,6,3,5],[2,1,5,3,6,4],[2,1,5,6,3,4],[2,1,5,6,4,3],[2,1,6,3,4,5],[2,1,6,5,3,4],[2,1,6,5,4,3],[2,3,1,5,6,4],[2,3,1,6,4,5],[2,3,4,1,6,5],[2,3,4,5,6,1],[2,3,4,6,1,5],[2,3,5,1,6,4],[2,3,5,6,1,4],[2,3,5,6,4,1],[2,3,6,1,4,5],[2,3,6,5,1,4],[2,3,6,5,4,1],[2,4,1,3,6,5],[2,4,1,5,6,3],[2,4,1,6,3,5],[2,4,5,1,6,3],[2,4,5,3,6,1],[2,4,5,6,1,3],[2,4,5,6,3,1],[2,4,6,1,3,5],[2,4,6,3,1,5],[2,4,6,5,1,3],[2,4,6,5,3,1],[2,5,1,3,6,4],[2,5,1,6,3,4],[2,5,1,6,4,3],[2,5,4,1,6,3],[2,5,4,3,6,1],[2,5,4,6,1,3],[2,5,4,6,3,1],[2,5,6,1,3,4],[2,5,6,1,4,3],[2,5,6,3,1,4],[2,5,6,3,4,1],[2,6,1,3,4,5],[2,6,1,5,3,4],[2,6,1,5,4,3],[2,6,4,1,3,5],[2,6,4,3,1,5],[2,6,4,5,1,3],[2,6,4,5,3,1],[2,6,5,1,3,4],[2,6,5,1,4,3],[2,6,5,3,1,4],[2,6,5,3,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6,4,3,1,2],[5,6,4,3,2,1],[6,1,2,3,4,5],[6,1,2,5,3,4],[6,1,2,5,4,3],[6,1,4,2,3,5],[6,1,4,3,2,5],[6,1,4,5,2,3],[6,1,4,5,3,2],[6,1,5,2,3,4],[6,1,5,2,4,3],[6,1,5,3,2,4],[6,1,5,3,4,2],[6,3,1,2,4,5],[6,3,1,5,2,4],[6,3,1,5,4,2],[6,3,2,1,4,5],[6,3,2,5,1,4],[6,3,2,5,4,1],[6,3,4,1,2,5],[6,3,4,2,1,5],[6,3,4,5,1,2],[6,3,4,5,2,1],[6,3,5,1,2,4],[6,3,5,1,4,2],[6,3,5,2,1,4],[6,3,5,2,4,1],[6,4,1,2,3,5],[6,4,1,3,2,5],[6,4,1,5,2,3],[6,4,1,5,3,2],[6,4,2,1,3,5],[6,4,2,3,1,5],[6,4,2,5,1,3],[6,4,2,5,3,1],[6,4,5,1,2,3],[6,4,5,1,3,2],[6,4,5,2,1,3],[6,4,5,2,3,1],[6,4,5,3,1,2],[6,4,5,3,2,1],[6,5,1,2,3,4],[6,5,1,2,4,3],[6,5,1,3,2,4],[6,5,1,3,4,2],[6,5,2,1,3,4],[6,5,2,1,4,3],[6,5,2,3,1,4],[6,5,2,3,4,1],[6,5,4,1,2,3],[6,5,4,1,3,2],[6,5,4,2,1,3],[6,5,4,2,3,1],[6,5,4,3,1,2],[6,5,4,3,2,1]]
265
stderr
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit