Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Main {
  4.  
  5. static ArrayList<Integer> qzahlen = new ArrayList<Integer>();
  6.  
  7. public static void main(String[] args) {
  8. qzahlen.add(4);
  9. qzahlen.add(9);
  10. qzahlen.add(16);
  11. qzahlen.add(25);
  12. qzahlen.add(36);
  13.  
  14. for (int i = 1; i <= 15; i++) {
  15. verketter(0, i, new ArrayList<Integer>());
  16. }
  17.  
  18. }
  19.  
  20. static boolean verketter(int index, int momentan, ArrayList<Integer> used) {
  21.  
  22. used.add(momentan);
  23. if (index == 14) {
  24. if (qzahlen.contains((Integer) used.get(13) + used.get(14))) {
  25. for (int i = 0; i < 15; i++) {
  26. System.out.print(used.get(i) + " ");
  27.  
  28. }
  29.  
  30. System.out.println(" PASST ");
  31. }
  32. return true;
  33. }
  34.  
  35. for (int i = 15; i > 0; i--) {
  36.  
  37. if (used.contains(i)) {
  38.  
  39. } else {
  40. if (qzahlen.contains(momentan + i)) {
  41. verketter(index + 1, i, used);
  42. }
  43.  
  44. }
  45. }
  46.  
  47. return true;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement