Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. private static final int SHUFFLE_COUNT = 5;
  2.  
  3.  
  4. private static int[] VALUES = {1, 2, 3, 4, 5, 6};
  5.  
  6.  
  7. //broken for when SHUFFLECOUNT and VALUES are EVEN
  8. public static void perfectShuffle(int[] values) {
  9. int[] values1 = Arrays.copyOf(values, values.length);
  10. int k = 0;
  11. for(int j = 0; j <= values.length / 2; j++) {
  12. values[k] = values1[j];
  13. k = k + 2;
  14. }
  15. k = 1;
  16. for(int j = (values.length / 2) + 1; j < values.length; j++) {
  17. values[k] = values1[j];
  18. k = k + 2;
  19. }
  20.  
  21. }
  22.  
  23. public void testPerfectShuffle() {
  24. System.out.println("Results of " + SHUFFLE_COUNT +
  25. " consecutive perfect shuffles:");
  26. for (int j = 1; j <= SHUFFLE_COUNT; j++) {
  27. perfectShuffle(VALUES);
  28. System.out.println(" " + j + ":" + Arrays.toString(VALUES));
  29. }
  30. System.out.println();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement