diff options
Diffstat (limited to 'Java/Magic.java')
-rw-r--r-- | Java/Magic.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Java/Magic.java b/Java/Magic.java new file mode 100644 index 0000000..6633639 --- /dev/null +++ b/Java/Magic.java @@ -0,0 +1,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. |