@@ -0,0 +1,1762 @@
+package coding4fun;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Write a function that takes inputs n and x and outputs the number of times%0A * we need to shuffle a deck of n cards, so that the deck goes back to its%0A * original state.%0A * %0A * We divide the deck into deck A: n-x cards and deck B: x cards. We shuffle the%0A * cards by always taking a card from the bottom of the deck and place it to%0A * the top of the deck.%0A * %0A * %3Cpre%3E%0A * Original state:%0A * Deck A  Deck B%0A * %5B0, 1%5D  %5B0, 1, 2%5D%0A * %0A * After shuffling:%0A * Deck A  Deck B%0A * %5B1, 0%5D  %5B1, 2, 0%5D%0A * %5B0, 1%5D  %5B2, 0, 1%5D%0A * %5B1, 0%5D  %5B0, 1, 2%5D%0A * %5B0, 1%5D  %5B1, 2, 0%5D%0A * %5B1, 0%5D  %5B2, 0, 1%5D%0A * %5B0, 1%5D  %5B0, 1, 2%5D (original state)%0A * %0A * Input: n = 5, x = 3%0A * Output: 6%0A * %3C/pre%3E%0A */%0Apublic class Problem6 %7B%0A    private static int shuffle(int n, int x) %7B%0A        int%5B%5D a = new int%5Bn-x%5D;%0A        for (int i = 0; i %3C a.length; i++) %7B%0A            a%5Bi%5D = i;%0A        %7D%0A        int%5B%5D aOriginal = Arrays.copyOf(a, a.length);%0A        int%5B%5D b = new int%5Bx%5D;%0A        for (int i = 0; i %3C b.length; i++) %7B%0A            b%5Bi%5D = i;%0A        %7D%0A        int%5B%5D bOriginal = Arrays.copyOf(b, b.length);%0A        %0A        int count = 0;%0A        while (true) %7B%0A            shuffle(a);%0A            shuffle(b);%0A            System.out.println(Arrays.toString(a) + %22 %22 + Arrays.toString(b));%0A            count++;%0A            if (Arrays.equals(a, aOriginal) && Arrays.equals(b, bOriginal)) %7B%0A                break;%0A            %7D%0A        %7D%0A        return count;%0A    %7D%0A    %0A    private static void shuffle(int%5B%5D a) %7B%0A        int tmp = a%5B0%5D;%0A        for (int i = 0; i %3C a.length-1; i++) %7B%0A            a%5Bi%5D = a%5Bi+1%5D;%0A        %7D%0A        a%5Ba.length-1%5D = tmp;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(shuffle(5, 3));%0A    %7D%0A%7D%0A

Add problem 6