Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final int SHUFFLE_COUNT = 5;
- private static int[] VALUES = {1, 2, 3, 4, 5, 6};
- //broken for when SHUFFLECOUNT and VALUES are EVEN
- public static void perfectShuffle(int[] values) {
- int[] values1 = Arrays.copyOf(values, values.length);
- int k = 0;
- for(int j = 0; j <= values.length / 2; j++) {
- values[k] = values1[j];
- k = k + 2;
- }
- k = 1;
- for(int j = (values.length / 2) + 1; j < values.length; j++) {
- values[k] = values1[j];
- k = k + 2;
- }
- }
- public void testPerfectShuffle() {
- System.out.println("Results of " + SHUFFLE_COUNT +
- " consecutive perfect shuffles:");
- for (int j = 1; j <= SHUFFLE_COUNT; j++) {
- perfectShuffle(VALUES);
- System.out.println(" " + j + ":" + Arrays.toString(VALUES));
- }
- System.out.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement