Skip to content

Instantly share code, notes, and snippets.

@zeagord
Created October 17, 2017 08:45
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 zeagord/b396f7a3f29f44bd9606f2d258471a19 to your computer and use it in GitHub Desktop.
Save zeagord/b396f7a3f29f44bd9606f2d258471a19 to your computer and use it in GitHub Desktop.
/**
* Created by rg3 on 10/17/17.
*/
import java.util.ArrayList;
public class NoOfStories {
static int small=1;
static int large=2;
public static ArrayList<ArrayList<String>> combinations(int stories) {
ArrayList<ArrayList<String>> result = new ArrayList<>();
//start from an empty list
result.add(new ArrayList<>());
for (int i = 0; i < stories; i++) {
//list of list in current iteration of the array stories
ArrayList<ArrayList<String>> current = new ArrayList<>();
for (ArrayList<String> l : result) {
// # of locations to insert is largest index + 1
for (int j = 0; j < l.size()+1; j++) {
// + add stories[i] to different locations
if (j/large ==0) {
l.add(j, "small");
} else {
l.add(j, "large");
}
//l.add(j, i);
ArrayList<String> temp = new ArrayList<>(l);
current.add(temp);
//System.out.println(temp);
// - remove stories[i] add
l.remove(j);
}
}
result = new ArrayList<ArrayList<String>>(current);
}
return result; }
public static void main(String[] args) {
System.out.println(combinations(3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment