fix: generate permutations more efficiently (avoid mem fault)