Skip to content

Instantly share code, notes, and snippets.

@KevinTyrrell
Last active July 9, 2017 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KevinTyrrell/757f34453632bb1a8529515930e74af0 to your computer and use it in GitHub Desktop.
Save KevinTyrrell/757f34453632bb1a8529515930e74af0 to your computer and use it in GitHub Desktop.
final String[][] clothing = new String[][] {
{ "Cap", "Bandana" },
{ "Vest", "Blazer", "T-Shirt" },
{ "Jeans", "Shorts" },
{ "Shoes" }
};
int permutations = 1;
for (final String[] i : clothing)
permutations *= i.length;
int[] combo = new int[clothing.length];
for (int i = 0; i < permutations; i++)
{
// Print this permutation.
for (int j = 0; j < items.length; j++)
Sytem.out.printf("%s ", clothing[j][combo[j]]);
System.out.println();
for (int j = 0; j < combo.length; j++)
{
if (++combo[j] < clothing[j].length) break;
combo[j] = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment