Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fermat {
- public static Set<List<String>> threadings(int n, Set<String> colours) {
- if (n == 0) {
- return Collections.singleton(new ArrayList<>());
- }
- Set<List<String>> previousThreadings = threadings(n - 1, colours);
- Set<List<String>> finalResult = new LinkedHashSet<>();
- for (List<String> beadList : previousThreadings) {
- for (String colour : colours) {
- List<String> newBeadList = new ArrayList<>(beadList);
- newBeadList.add(colour);
- finalResult.add(newBeadList);
- }
- }
- return finalResult;
- }
- public static void main(String[] args) {
- Set<String> colours = new HashSet<>();
- colours.add("red");
- colours.add("green");
- colours.add("blue");
- System.out.println(threadings(2, colours));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement