Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.claude_martin.playground;
- import java.util.Arrays;
- public class SomeClass {
- public static void main(String[] args) {
- // number of tries:
- final int n = 5;
- // initialized as [0,0,0,0,0],
- // which is not a valid result
- final byte[] points = new byte[n];
- // initially the sum is 0;
- for (int sum = 0; sum < 3 * n; ) {
- // Get next combination:
- for (int j = 0; true; ++j) {
- if (points[j] == 3) {
- points[j] = 0;
- sum -= 3;
- } else {
- ++points[j];
- ++sum;
- break;
- }
- }
- if (sum == n) // valid result?
- System.out.println(Arrays.toString(points));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement