Then put a 1 at the end of each permutation. Then put a 4 at the end of each permutation. The put a 5 at the end of each permutation. Then put a 6 at the end of each permutation. Ultimately, if you want all permutations of numbers 1-6, that’s the same as concatenating the following 6 sets together: The other method I came up with, and arguably a more elegant method, involves recursion. I think this involves 2586 iterations, which is good, but might not be the best. The whole adding and subtracting method was the first thing that came to mind, but there’s probably another better way of doing that. You might also notice that we didn’t even have to use loops for the 6th index because we instead just found whichever one hadn’t been used yet. I'm being ambiguous here because there are many ways to store your list add permutation a,b,c,d,e,f to your list Start by editing this line (39) so the list is the elements you want to perm, IntList base = new IntList(1, 2, 3, 4, 5, 6) // factorial(int n) # permutations('ABCD', 2) -> AB AC AD BA BC BD CA CB CD DA DB DC It is very idiomatically Python – the use of a separate index lookup, of slicing, and of reversed() – so it doesn’t translate well to Java, but it is pretty interesting as an approach.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |