In orden to list all derangements of five elements, I wrote the following (very ugly) code:
elementos = {Red, Blue, Green, Orange, Black};
permutaciones = Permutations[elementos];
desarreglos = Select[permutaciones, #[[1]]!=elementos[[1]]&&#[[2]]!=elementos[[2]]&&#[[3]]!=elementos[[3]]&&#[[4]]!=elementos[[4]]&&#[[5]]!=elementos[[5]]&];
Length[desarreglos];
desarreglos//Grid
I am unable to figure out how to avoid writing all the #[[i]]!=elementos[[i]]
stuff.
Any help would be highly appreciated.
TIA.
ResourceFunction["Derangements"]
$\endgroup$