# No Repeats Please - Help

I’m having a lot of trouble solving the “No repeats please” algorithm (Front End - Advanced Algorithm Scripting) and I was hoping someone could sheds some light on it for me.

I understand that I’m supposed to use Heap’s Algorithm and I have no issue understanding Heap’s on a conceptual level, but I have no idea how to implement it in JS. It looks like I have to recurse down multiple levels (ex: first recursion - output A, next recursion - output B, next recursion - output C, then spit out ABC), but then walk my way back up through each step of the recursion (ex: now that I’ve spit out ABC, I need to walk back one level of recursion and output C [instead of B], then next recursion - output B and spit out ACB) and that’s what I’m having trouble with.

I don’t understand how I’m supposed to go all the way through a set of recursions, then output a result, and then go back in time to the previous step or two in that set of recursions.

I need help.

Maybe it’s not helpful to you, I just followed Wiki explanation, write the code as it says on the Wiki page…

I mean this:

First we set a counter i to 0. Now we perform the following steps repeatedly until i is equal to n. We use the algorithm to generate the (n−1)! permutations of the first n−1 elements, adjoining the last element to each of these. This generates all of the permutations that end with the last element. Then if n is odd, we switch the first element and the last one, while if n is even we can switch the ith element and the last one (there is no difference between n even and odd in the first iteration). We add one to the counter i and repeat.

It would be nice to have a link to the wiki page rather than just a quote from it.
I can’t see what n is?