Created
April 27, 2018 20:21
-
-
Save smaugho/f18040e9422587082db5dacccf2e7777 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
public class RunningClass { | |
public static void main(String [] args) | |
{ | |
List<String> list = new LinkedList<>(); | |
process(Collections.singletonList("2890"), list); | |
for (String element : list) { | |
System.out.println(element); | |
} | |
} | |
public static void process(List<String> parts, List<String> list) { | |
for (int partIndex = 0; partIndex < parts.size(); partIndex++) { | |
String part = parts.get(partIndex); | |
List<String> previousPart = partIndex > 0? parts.subList(0, partIndex) : null; | |
List<String> lastParts = partIndex < parts.size() - 1? parts.subList(partIndex + 1, parts.size()) : null; | |
for (int i = 1; i < part.length(); i++) { | |
List newParts = new LinkedList(); | |
if (previousPart != null) newParts.addAll(previousPart); | |
newParts.add(part.substring(0, i)); | |
newParts.add(part.substring(i)); | |
if (lastParts != null) newParts.addAll(lastParts); | |
process(newParts, list); | |
} | |
} | |
String result = ""; | |
for (String part : parts) { | |
result = result + part + " "; | |
} | |
result = result.trim(); | |
if (!list.contains(result)) { | |
list.add(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment