Skip to content

Instantly share code, notes, and snippets.

@maxfunke
Created May 9, 2014 09:03
Show Gist options
  • Save maxfunke/3c3aa830e2b93d502cc9 to your computer and use it in GitHub Desktop.
Save maxfunke/3c3aa830e2b93d502cc9 to your computer and use it in GitHub Desktop.
recursive permutation (same length, different order)
private static void recPermute(String soFar, String rest) {
if (rest.equals( "" )) {
System.out.println( soFar );
} else {
for (int i = 0; i < rest.length(); i++) {
String next = soFar + rest.charAt(i);
String remaining = rest.substring(0, i) + rest.substring(i+1);
recPermute(next, remaining);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment