fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int move=0;
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. System.out.println(solve(2,"A","B","C"));
  14. move = 0;
  15. System.out.println(solve(3,"A","B","C"));
  16. move = 0;
  17. System.out.println(solve(4,"A","B","C"));
  18. }
  19.  
  20. public static String solve(int n, String start, String middle, String end) {
  21. if (n == 1) {
  22. move++;
  23. return Integer.toString(move);
  24. }
  25.  
  26. solve(n - 1, start, end, middle);
  27. move++;
  28. return solve(n - 1, middle, start, end);
  29. }
  30. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
3
7
15