Skip to content

Instantly share code, notes, and snippets.

@jbleduigou
Created December 11, 2019 21:56
Show Gist options
  • Save jbleduigou/28266f604ee4aca9467281d0ae711f25 to your computer and use it in GitHub Desktop.
Save jbleduigou/28266f604ee4aca9467281d0ae711f25 to your computer and use it in GitHub Desktop.
private static Set<List<Item>> generateAllSubLists(List<Item> items) {
Set<List<Item>> subLists = new HashSet<>();
int allBitMasks = (int) Math.pow(2, Math.min(items.size(), 12));
for (long i = 1; i < allBitMasks; i++) {
List<Item> sublist = new ArrayList<>();
for (int j = 0; j < items.size(); j++) {
if ((i & (1 << j)) > 0) {
sublist.add(items.get(j));
}
}
subLists.add(sublist);
}
return subLists;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment