Created
December 11, 2019 21:56
-
-
Save jbleduigou/28266f604ee4aca9467281d0ae711f25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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