summaryrefslogtreecommitdiffstats
path: root/Java/Magic.java
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /Java/Magic.java
downloadschool-code-9d53d8857eaa1c9405894a88ca75bc4657e42f35.tar.gz
school-code-9d53d8857eaa1c9405894a88ca75bc4657e42f35.tar.bz2
school-code-9d53d8857eaa1c9405894a88ca75bc4657e42f35.zip
Inital CommitHEADmaster
Diffstat (limited to 'Java/Magic.java')
-rw-r--r--Java/Magic.java84
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.