Suppose we have the alphabet "abcdefghiklimnop". How can I recursively generate permutations repeating this alphabet in FIVE groups in an efficient way?
I struggled with this a few days later. Any feedback would be helpful.
Essentially this is the same as: Generating all permutations of a given string
However, I just want the permutations to be FIVE-wide throughout the line. And I could not understand it.
SO for all substrings of length 5 "abcdefghiklimnop", find permutations of the substring. For example, if the substring was abcdef, I would like all permutations of this, or if the substring was defli, I would like all permutations of this substring. The code below gives me all permutations of a string, but I would like to use to find all permutations of all substrings of size 5 rows.
public static void permutation(String str) { permutation("", str); } private static void permutation(String prefix, String str) { int n = str.length(); if (n == 0) System.out.println(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n)); } }
source share