Created
October 17, 2017 08:45
-
-
Save zeagord/b396f7a3f29f44bd9606f2d258471a19 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
/** | |
* 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