Advertisement
DulcetAirman

basketball 2

May 22nd, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.claude_martin.playground;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class SomeClass {
  6.  
  7.     public static void main(String[] args) {
  8.         // number of tries:
  9.         final int n = 5;
  10.         // initialized as [0,0,0,0,0],
  11.         // which is not a valid result
  12.         final byte[] points = new byte[n];
  13.         // initially the sum is 0;
  14.         for (int sum = 0; sum < 3 * n; ) {
  15.             // Get next combination:
  16.             for (int j = 0; true; ++j) {
  17.                 if (points[j] == 3) {
  18.                     points[j] = 0;
  19.                     sum -= 3;
  20.                 } else {
  21.                     ++points[j];
  22.                     ++sum;
  23.                     break;
  24.                 }
  25.             }
  26.  
  27.             if (sum == n) // valid result?
  28.                 System.out.println(Arrays.toString(points));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement