Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Main {
- static ArrayList<Integer> qzahlen = new ArrayList<Integer>();
- public static void main(String[] args) {
- qzahlen.add(4);
- qzahlen.add(9);
- qzahlen.add(16);
- qzahlen.add(25);
- qzahlen.add(36);
- for (int i = 1; i <= 15; i++) {
- verketter(0, i, new ArrayList<Integer>());
- }
- }
- static boolean verketter(int index, int momentan, ArrayList<Integer> used) {
- used.add(momentan);
- if (index == 14) {
- if (qzahlen.contains((Integer) used.get(13) + used.get(14))) {
- for (int i = 0; i < 15; i++) {
- System.out.print(used.get(i) + " ");
- }
- System.out.println(" PASST ");
- }
- return true;
- }
- for (int i = 15; i > 0; i--) {
- if (used.contains(i)) {
- } else {
- if (qzahlen.contains(momentan + i)) {
- verketter(index + 1, i, used);
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement