Set, the card game: Difference between revisions
Content added Content deleted
(New post.) |
|||
Line 173: | Line 173: | ||
private static List<Card> createPackOfCards() { |
private static List<Card> createPackOfCards() { |
||
List<Card> pack = new ArrayList<Card>(); |
List<Card> pack = new ArrayList<Card>(81); |
||
for ( Number number : Number.values() ) { |
for ( Number number : Number.values() ) { |
||
for ( Colour colour : Colour.values() ) { |
for ( Colour colour : Colour.values() ) { |
||
Line 198: | Line 198: | ||
} |
} |
||
private static <T> List<List<T>> combinations(List<T> list, int |
private static <T> List<List<T>> combinations(List<T> list, int choose) { |
||
List<List<T>> combinations = new ArrayList<List<T>>(); |
List<List<T>> combinations = new ArrayList<List<T>>(); |
||
List<Integer> combination = IntStream.range(0, |
List<Integer> combination = IntStream.range(0, choose).boxed().collect(Collectors.toList()); |
||
while ( combination.get( |
while ( combination.get(choose - 1) < list.size() ) { |
||
combinations.add(combination.stream().map( i -> list.get(i) ).toList()); |
combinations.add(combination.stream().map( i -> list.get(i) ).toList()); |
||
int |
int temp = choose - 1; |
||
while ( |
while ( temp != 0 && combination.get(temp) == list.size() - choose + temp ) { |
||
temp -= 1; |
|||
} |
} |
||
combination.set( |
combination.set(temp, combination.get(temp) + 1); |
||
for ( int i = |
for ( int i = temp + 1; i < choose; i++ ) { |
||
combination.set(i, combination.get(i - 1) + 1); |
combination.set(i, combination.get(i - 1) + 1); |
||
} |
} |