Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. public class First {
  2.  
  3. public static void main(String[] args) {
  4. Percolation.init();
  5. Percolation.print();
  6. System.out.println();
  7. //Percolation.is_percolation(0);
  8. //Percolation.is_percolation(1);
  9. //Percolation.is_percolation(2);
  10. //Percolation.is_percolation(3);
  11. //Percolation.is_percolation( 4);
  12. //Percolation.is_percolation(6);
  13. //Percolation.is_percolation(6);
  14. Percolation.is_percolation(11);
  15. //Percolation.is_percolation(8);
  16. //boolean up = false;
  17. //int n = 5;
  18. //int size = 6;
  19. //if ((up && (n % size == 0)) || (!up && ((n+1) % size == 0))) {
  20. // System.out.println("Im here 1 condition" + n);
  21. //}
  22. }
  23.  
  24. }
  25.  
  26.  
  27.  
  28. public class Percolation {
  29. static int size = 4;
  30. static int length = size * size;
  31. static boolean[] grid = new boolean[length];
  32. public static void init() {
  33. for (int i = 0; i < grid.length; i++) {
  34. grid[i] = false;
  35. }
  36. grid[0] = true;
  37. grid[1] = true;
  38. grid[2] = true;
  39. grid[6] = true;
  40. grid[9] = true;
  41. grid[10] = true;
  42. grid[11] = true;
  43. grid[14] = true;
  44. grid[15] = true;
  45. }
  46. public static void print() {
  47. for (int i = 0; i < size; i++) {
  48. //System.out.println(i);
  49. int k = i;
  50. while (k < length) {
  51. System.out.print(toEtoileOuTiret(grid[k]));
  52. k = k + size;
  53. }
  54. System.out.println();
  55. }
  56. }
  57. public static boolean detect_path(boolean[] seen, int n, boolean up) {
  58. seen[n] = true;
  59.  
  60. for (int i = 0; i < size; i++) {
  61. //System.out.println(i);
  62. int k = i;
  63. while (k < length) {
  64. System.out.print(toEtoileOuTiret(seen[k]));
  65. k = k + size;
  66. }
  67. System.out.println();
  68. }
  69. System.out.println();
  70.  
  71. if ((up && (n % size == 0)) || (!up && ((n+1) % size == 0))) {
  72. System.out.println("Im here 1 condition " + n);
  73. return true;
  74. }
  75. if (n - 1 >= 0) {
  76. if ((seen[n-1] == false) & (grid[n-1] == true)) {
  77. System.out.println("Up");
  78. System.out.println("Im here 2 condition " + n);
  79. return detect_path(seen, n - 1, up);
  80. }
  81. }
  82. if (n + 1 < length) {
  83. if ((seen[n+1] == false) & (grid[n+1] == true)) {
  84. System.out.println("Down");
  85. System.out.println("Im here 3 condition " + n);
  86. return detect_path(seen, n + 1, up);
  87. }
  88. }
  89.  
  90. if (n - size >= 0) {
  91. if ((seen[n - size] == false) & (grid[n - size] == true)) {
  92. System.out.println("Left");
  93. System.out.println("Im here 4 condition " + n);
  94. return detect_path(seen, n - size, up);
  95. }
  96. }
  97. if (n + size < length) {
  98. if ((seen[n + size] == false) & (grid[n + size] == true)) {
  99. System.out.println("Right");
  100. System.out.println("Im here 5 condition " + n);
  101. return detect_path(seen, n + size, up);
  102. }
  103. }
  104. //experiment
  105. //experiment
  106. return false;
  107. }
  108. public static void is_percolation(int n) {
  109. boolean[] seen = new boolean[length];
  110. boolean f1 = detect_path(seen, n, true);
  111. boolean f2 = detect_path(seen, n, false);
  112. System.out.println("Up side is " + f1);
  113. System.out.println("Down side is " + f2);
  114. }
  115. public static void random_shadow() {
  116. int index = (int) (Math.random() * length);
  117. grid[index] = true;
  118. }
  119. public static void printMas() {
  120. for (int i = 0; i < length; i++) {
  121. System.out.print(grid[i]);
  122. System.out.print(' ');
  123. System.out.println();
  124. }
  125. }
  126. private static char toEtoileOuTiret(boolean k) {
  127. if (k){
  128. return '*';
  129. }
  130. else {
  131. return '-';
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement