@@ -0,0 +1,1366 @@
+import java.util.Arrays;%0Aimport java.util.Stack;%0A%0Apublic class Hanoi %7B%0A%0A    Stack%3CInteger%3E sourcePeg = new Stack%3CInteger%3E();%0A    Stack%3CInteger%3E targetPeg = new Stack%3CInteger%3E();%0A    Stack%3CInteger%3E helperPeg = new Stack%3CInteger%3E();%0A%0A    private void solve(int disks) %7B%0A        for (int i = disks; i %3E 0; i--) %7B%0A            sourcePeg.push(i);%0A        %7D%0A        System.out.println(%22Playing Hanoi for %22 + disks + %22 disks:%5Cn%22);%0A        showPegs();%0A        move(disks, sourcePeg, targetPeg, helperPeg);%0A        System.out.println(%22Solved.%22);%0A    %7D%0A%0A    private void move(int n, Stack%3CInteger%3E sourcePeg, Stack%3CInteger%3E targetPeg, Stack%3CInteger%3E helperPeg) %7B%0A        if (n %3E 0) %7B%0A            if (n %3E 1) %7B%0A                move(n - 1, sourcePeg, helperPeg, targetPeg);%0A            %7D%0A            targetPeg.push(sourcePeg.pop());%0A            showPegs();%0A            if (n %3E 1) %7B%0A                move(n - 1, helperPeg, targetPeg, sourcePeg);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void showPegs() %7B%0A        System.out.println(%22sourcePeg = %22 + Arrays.toString(sourcePeg.toArray()));%0A        System.out.println(%22helperPeg = %22 + Arrays.toString(helperPeg.toArray()));%0A        System.out.println(%22targetPeg = %22 + Arrays.toString(targetPeg.toArray()) + %22%5Cn%22);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Hanoi hanoi = new Hanoi();%0A        hanoi.solve(5);%0A    %7D%0A%7D%0A

add hanoi challenge