Permutations without returning lists. Uglier but less memory overhead. Easily translatable to C.