Generate all permutations without external libraries.