Guest User

Untitled

a guest
Aug 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public class FortyPounds {
  2.  
  3. static final int[] s = {-1, 0, 1};
  4.  
  5. public static void main(String[] args) {
  6. for (int w1 = 1; w1 <= 37; w1++)
  7. for (int w2 = 1; w2 <= 38 - w1; w2++)
  8. W3: for (int w3 = 1; w3 <= 39 - w1 - w2; w3++) {
  9. int w4 = 40 - w1 - w2 - w3;
  10. W: for (int w = 1; w <= 40; w++) {
  11. for (int s1 : s) for (int s2 : s) for (int s3 : s) for (int s4 : s)
  12. if (w == w1 * s1 + w2 * s2 + w3 * s3 + s4 * w4)
  13. continue W;
  14. continue W3;
  15. }
  16. System.out.println(String.format("%s %s %s %s", w1, w2, w3, w4));
  17. }
  18. }
  19.  
  20. }
  21.  
  22.  
  23. /* Output:
  24. 1, 3, 9, 27
  25. 1, 3, 27, 9
  26. 1, 9, 3, 27
  27. 1, 9, 27, 3
  28. 1, 27, 3, 9
  29. 1, 27, 9, 3
  30. 3, 1, 9, 27
  31. 3, 1, 27, 9
  32. 3, 9, 1, 27
  33. 3, 9, 27, 1
  34. 3, 27, 1, 9
  35. 3, 27, 9, 1
  36. 9, 1, 3, 27
  37. 9, 1, 27, 3
  38. 9, 3, 1, 27
  39. 9, 3, 27, 1
  40. 9, 27, 1, 3
  41. 9, 27, 3, 1
  42. 27, 1, 3, 9
  43. 27, 1, 9, 3
  44. 27, 3, 1, 9
  45. 27, 3, 9, 1
  46. 27, 9, 1, 3
  47. 27, 9, 3, 1
  48. */
Add Comment
Please, Sign In to add comment