Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class First {
- public static void main(String[] args) {
- Percolation.init();
- Percolation.print();
- System.out.println();
- //Percolation.is_percolation(0);
- //Percolation.is_percolation(1);
- //Percolation.is_percolation(2);
- //Percolation.is_percolation(3);
- //Percolation.is_percolation( 4);
- //Percolation.is_percolation(6);
- //Percolation.is_percolation(6);
- Percolation.is_percolation(11);
- //Percolation.is_percolation(8);
- //boolean up = false;
- //int n = 5;
- //int size = 6;
- //if ((up && (n % size == 0)) || (!up && ((n+1) % size == 0))) {
- // System.out.println("Im here 1 condition" + n);
- //}
- }
- }
- public class Percolation {
- static int size = 4;
- static int length = size * size;
- static boolean[] grid = new boolean[length];
- public static void init() {
- for (int i = 0; i < grid.length; i++) {
- grid[i] = false;
- }
- grid[0] = true;
- grid[1] = true;
- grid[2] = true;
- grid[6] = true;
- grid[9] = true;
- grid[10] = true;
- grid[11] = true;
- grid[14] = true;
- grid[15] = true;
- }
- public static void print() {
- for (int i = 0; i < size; i++) {
- //System.out.println(i);
- int k = i;
- while (k < length) {
- System.out.print(toEtoileOuTiret(grid[k]));
- k = k + size;
- }
- System.out.println();
- }
- }
- public static boolean detect_path(boolean[] seen, int n, boolean up) {
- seen[n] = true;
- for (int i = 0; i < size; i++) {
- //System.out.println(i);
- int k = i;
- while (k < length) {
- System.out.print(toEtoileOuTiret(seen[k]));
- k = k + size;
- }
- System.out.println();
- }
- System.out.println();
- if ((up && (n % size == 0)) || (!up && ((n+1) % size == 0))) {
- System.out.println("Im here 1 condition " + n);
- return true;
- }
- if (n - 1 >= 0) {
- if ((seen[n-1] == false) & (grid[n-1] == true)) {
- System.out.println("Up");
- System.out.println("Im here 2 condition " + n);
- return detect_path(seen, n - 1, up);
- }
- }
- if (n + 1 < length) {
- if ((seen[n+1] == false) & (grid[n+1] == true)) {
- System.out.println("Down");
- System.out.println("Im here 3 condition " + n);
- return detect_path(seen, n + 1, up);
- }
- }
- if (n - size >= 0) {
- if ((seen[n - size] == false) & (grid[n - size] == true)) {
- System.out.println("Left");
- System.out.println("Im here 4 condition " + n);
- return detect_path(seen, n - size, up);
- }
- }
- if (n + size < length) {
- if ((seen[n + size] == false) & (grid[n + size] == true)) {
- System.out.println("Right");
- System.out.println("Im here 5 condition " + n);
- return detect_path(seen, n + size, up);
- }
- }
- //experiment
- //experiment
- return false;
- }
- public static void is_percolation(int n) {
- boolean[] seen = new boolean[length];
- boolean f1 = detect_path(seen, n, true);
- boolean f2 = detect_path(seen, n, false);
- System.out.println("Up side is " + f1);
- System.out.println("Down side is " + f2);
- }
- public static void random_shadow() {
- int index = (int) (Math.random() * length);
- grid[index] = true;
- }
- public static void printMas() {
- for (int i = 0; i < length; i++) {
- System.out.print(grid[i]);
- System.out.print(' ');
- System.out.println();
- }
- }
- private static char toEtoileOuTiret(boolean k) {
- if (k){
- return '*';
- }
- else {
- return '-';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement