Guest User

Untitled

a guest
Jan 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1.  
  2. //this is the start for the solve method og recsolve
  3. class recsolve {
  4.  
  5. public static void main(String[] ar) {
  6. /*the arrays are like
  7. a[0] holds number of disks
  8. a[1] holds pole number
  9. */
  10. int disks = 5; //number of disks
  11.  
  12. int[] a = new int[disks + 2];
  13. int[] c = new int[disks + 2];
  14. int[] b = new int[disks + 2];
  15.  
  16.  
  17. //start pole is a
  18. for (int i = disks + 1; i > 1; --i) {
  19. a[i] = disks - i + 2;//the disks at start
  20. b[i] = c[i] = 0;
  21. }
  22. a[0] = disks;
  23. b[0] = c[0] = 0;
  24. a[1] = 1;
  25. b[1] = 2;
  26. c[1] = 3;
  27.  
  28. for (int i = 0; i < disks+2; i++) {
  29. System.out.print(a[i] + " ");
  30. System.out.print(b[i] + " ");
  31. System.out.print(c[i] + "\n");
  32. }
  33. System.out.print("\n");
  34.  
  35. towerRec(a, b, c, disks);
  36.  
  37.  
  38. for (int i = 0; i < disks+2; i++) {
  39. System.out.print(a[i] + " ");
  40. System.out.print(b[i] + " ");
  41. System.out.print(c[i] + "\n");
  42. }
  43. System.out.print("\n");
  44. }
  45.  
  46. public static void towerRec(int[] src, int[] tmp, int[] dst, int disks) {
  47.  
  48. /*
  49. for (int i = disks + 1; i > 0; i--) {
  50. System.out.print(src[i] + " ");
  51. System.out.print(tmp[i] + " ");
  52. System.out.print(dst[i] + "\n\n");
  53.  
  54. }*/
  55. if (disks > 0) {
  56. towerRec(src, dst, tmp, disks - 1);
  57. dst[(++dst[0]) + 1] = src[(src[0]--) + 1];
  58. towerRec(tmp, src, dst, disks - 1);
  59. System.out.print("runned \n");
  60. }
  61. //System.out.print(dst);
  62. // else {System.out.println("done");
  63. // }
  64. }
  65.  
  66. }
Add Comment
Please, Sign In to add comment