summaryrefslogtreecommitdiffstats
path: root/Java/Magic.java
blob: 6633639acec0acd6dbdeccd0360e3fce2137908c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
class Magic {
    public static void main(String[] args) throws java.io.IOException{
	    int epoch = 2;
	    int prospectingX = 0;
            int prospectingY = 0;
	    boolean notFinished = true;
            boolean noneSelected = true;
	    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
            int cords = Integer.parseInt(input.readLine());
	    int[][] cordPlane = new int[cords][cords];
	    if (cords % 2 == 0){
		    System.exit(1);
	    } 
	    int maxLength = cordPlane.length - 1;
	    cordPlane[cords/2][0] = 1; //first cord is X second is Y
	    prospectingX = (cords/2)+1;
	    prospectingY = -1;
	    System.out.println("starting...");
	    while (epoch <= cords*cords && notFinished){
	    while(notFinished){



	    System.out.println("Epoch is " + epoch);

	    System.out.println("Testing if X-cord " + prospectingX + " is less than 0");
	    if(prospectingX < 0){
		prospectingX = prospectingX + cordPlane.length;
	    }

	    System.out.println("Testing if X-cord " + prospectingX + " is greater than " + maxLength);
	    if(prospectingX > maxLength){
        	prospectingX = prospectingX - cordPlane.length;
	    }

	    System.out.println("Testing if Y-cord " + prospectingY + " is less than 0");
	    if(prospectingY < 0){
		prospectingY = prospectingY + cordPlane.length;
	    }

	    System.out.println("Testing if Y-cord " + prospectingY + " is greater than " + maxLength);
	    if(prospectingY > maxLength){
		prospectingY = prospectingY - cordPlane.length;
	    }
            System.out.println("Rerouted everything... Testing now...");
            if( cordPlane[prospectingX][prospectingY] == 0 ){
	       System.out.println("Placing cord...");
	       cordPlane[prospectingX][prospectingY] = epoch;
	       prospectingX++;
	       prospectingY--;
	       epoch++;
	       notFinished = false;
	for (int k = 0; k < cordPlane.length; k++) { // loop through a multidimensional array
        for(int l = 0; l < cordPlane[k].length; l++) {
           System.out.print(cordPlane[l][k] + " ");
        }
           System.out.println();
		     }
	    } else {
		    prospectingY--;
		    System.out.println("Reducing Y to " + prospectingY);
	    }
	    
	    }
	    notFinished = true;
	    }
      for (int k = 0; k < cordPlane.length; k++) { // loop through a multidimensional array
        for(int l = 0; l < cordPlane[k].length; l++) {
           System.out.print(cordPlane[l][k] + " ");
	}
           System.out.println();
      }

    }
}



//By msglm; Released into the public domain.