diff --git a/.gitignore b/.gitignore index 25e95cc..ca7cd30 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,4 @@ /Semester 2/Assignments/MP1_CalebFontenot/target/ /Semester 2/Assignments/MP2_CalebFontenot/target/ /Semester 2/Assignments/lab2_CalebFontenot/target/ +/ASDV-Help/Mason/target/ diff --git a/ASDV-Help/Mason/pom.xml b/ASDV-Help/Mason/pom.xml new file mode 100644 index 0000000..c120f59 --- /dev/null +++ b/ASDV-Help/Mason/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + Mason + 1.0-SNAPSHOT + jar + + UTF-8 + 17 + 17 + com.calebfontenot.mason.Mason + + \ No newline at end of file diff --git a/ASDV-Help/Mason/src/main/java/com/calebfontenot/mason/Mason.java b/ASDV-Help/Mason/src/main/java/com/calebfontenot/mason/Mason.java new file mode 100644 index 0000000..ffc774a --- /dev/null +++ b/ASDV-Help/Mason/src/main/java/com/calebfontenot/mason/Mason.java @@ -0,0 +1,211 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.calebfontenot.mason; + +/** + * + * @author caleb + */ +public class Mason { + + public static void sortNames(char[][] names) + { + + for (int i = 0; i < names.length - 1; ++i) + { + + for (int j = i + 1; j < names.length; ++j) + { + //>compare character by character names[i] to names[j] + for (int index1 = 0, index2 = 0;//index1 to traverse names[i] + //index2 to traverse names[j] + index1 < names[i].length + && index2 < names[j].length; + ++index1, ++index2) + { + + //>>SWAP name[i] with names[j] + //if names[i] > names[j] OR the name at i has more chars after the tie + // ( i.e. if "bbbc" at names[i] and "bbb" at names[j] at j then we swap them ) + if (names[i][index1] > names[j][index2] + || (index2 == names[j].length - 1 && index1 < names[i].length - 1)) + { + //>> copy to tempI the names[i] + char[] temp = names[i]; + names[i] = names[j]; + names[j] = temp; + break;///you must break , no need to continue comparing characters at index1, index2 + } + //>>if the characters are equal, continue + if (names[i][index1] == names[j][index2]) + { + continue;//do nothing, but continue + } else //name at i is smaller than name + { + break; + } + } + } + } + + } + + public static void sortNames(char[][][] tables) + { + for (int numTable = 0; numTable < tables.length; ++numTable) + { + for (int i = 0; i < tables[numTable].length - 1; ++i) + { + + for (int j = i + 1; j < tables[numTable].length; ++j) + { + //>compare character by character names[i] to names[j] + for (int index1 = 0, index2 = 0;//index1 to traverse names[i] + //index2 to traverse names[j] + index1 < tables[i][i].length + && index2 < tables[j][i].length; + ++index1, ++index2) + { + + //>>SWAP name[i] with names[j] + //if names[i] > names[j] OR the name at i has more chars after the tie + // ( i.e. if "bbbc" at names[i] and "bbb" at names[j] at j then we swap them ) + if (tables[numTable][i][index1] > tables[numTable][j][index2] + || (index2 == tables[numTable][j].length - 1 && index1 < tables[numTable][i].length - 1)) + { + //>> copy to tempI the names[i] + char[][] temp = tables[i]; + tables[i] = tables[j]; + tables[j] = temp; + break;///you must break , no need to continue comparing characters at index1, index2 + } + //>>if the characters are equal, continue + if (tables[i][index1] == tables[j][index2]) + { + continue;//do nothing, but continue + } else //name at i is smaller than name + { + break; + } + } + } + } + } + } + + /** + * Prints row by row + * + * @param ar + */ + public static void printRowMajorOrder(char[][] ar) + { + for (int i = 0; i < ar.length; ++i) + { + for (int j = 0; j < ar[i].length; ++j) + { + System.out.print(ar[i][j]); + } + System.out.print(" "); + + } + } + + public static void printRowMajorOrder(char[][][] tables) + { + + for (int numTable = 0; numTable < tables.length; ++numTable) + { + for (int i = 0; i < tables[numTable].length; ++i) + { + for (int j = 0; j < tables[numTable][i].length; ++j) + { + System.out.print(tables[numTable][i][j]); + + } + System.out.print(" "); + + } + System.out.println(""); + } + + } + + public static void main(String[] args) + { + char[][] names = + { + { + 'j', 'o', 'h', 'n' + }, + { + 'a', 'n' + }, + { + 'b', 'y', 'r', 'o', 'n' + }, + { + 'b', 'y', 'r', 'o', 'n', 'i' + }, + { + 'a', 'a', 'o', 'n' + }, + { + 'b', 'b', 'b', 'b' + }, + { + 'b', 'b', 'b', 'c' + }, + { + 'b', 'b', 'b' + } + }; + + char[][][] tables = + { + { + { + 'j', 'o', 'h', 'n' + }, + { + 'a', 'n' + }, + { + 'b', 'y', 'r', 'o', 'n' + }, + { + 'b', 'y', 'r', 'o', 'n', 'i' + } + }, + { + { + 'a', 'a', 'o', 'n' + }, + { + 'b', 'b', 'b', 'b' + }, + { + 'b', 'b', 'b', 'c' + }, + { + 'b', 'b', 'b' + } + } + }; +// System.out.println("ORIGINAL LIST"); +// printRowMajorOrder(names); +// +// System.out.println("\n\nSORTED LIST"); +// sortNames(names); +// printRowMajorOrder(names); + + System.out.println("ORIGINAL LIST"); + printRowMajorOrder(tables); + System.out.println("\n\nSORTED LIST"); + sortNames(tables); + printRowMajorOrder(tables); + } + +} diff --git a/ASDV-Help/Mason/src/main/java/com/calebfontenot/mason/Mason_2.java b/ASDV-Help/Mason/src/main/java/com/calebfontenot/mason/Mason_2.java new file mode 100644 index 0000000..7fb3c37 --- /dev/null +++ b/ASDV-Help/Mason/src/main/java/com/calebfontenot/mason/Mason_2.java @@ -0,0 +1,143 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.calebfontenot.mason; + +/** + * + * @author caleb + */ +public class Mason_2 { + + public static int maxNumberOfColumnsInJagged2dArray(char[][] ar) { + int maxNumberOfColumns = 0; + for (int row = 0; row < ar.length; ++row) { + if (ar[row].length > maxNumberOfColumns) { + maxNumberOfColumns = ar[row].length; + } + } + + return maxNumberOfColumns; + } + + public static void printColumnMajorOrder(char[][] ar) { + int row = 0; + int column = 0; + int max = maxNumberOfColumnsInJagged2dArray(ar); + for (column = 0; column < max; ++column) { + + for (row = 0; row < ar.length; ++row) { + if (column < ar[row].length) { + System.out.print(ar[row][column] + " "); + } + } + System.out.println(""); + } + } + + public static void sortNames(char[][][] names) { + for (int numTable = 0; numTable < names.length; ++numTable) { + for (int i = 0; i < names[numTable].length - 1; ++i) { + + for (int j = i + 1; j < names[numTable].length; ++j) { + //>compare character by character names[i] to names[j] + for (int index1 = 0, index2 = 0;//index1 to traverse names[i] + //index2 to traverse names[j] + index1 < names[numTable][i].length + && index2 < names[numTable][j].length; + ++index1, ++index2) { + + //>>SWAP name[i] with names[j] + //if names[i] > names[j] OR the name at i has more chars after the tie + // ( i.e. if "bbbc" at names[i] and "bbb" at names[j] at j then we swap them ) + if (names[numTable][i][index1] > names[numTable][j][index2] + || (index2 == names[numTable][j].length - 1 && index1 < names[numTable][i].length - 1)) { + //>> copy to tempI the names[i] + char[] temp = names[numTable][i]; + names[numTable][i] = names[numTable][j]; + names[numTable][j] = temp; + break;///you must break , no need to continue comparing characters at index1, index2 + } + //>>if the characters are equal, continue + if (names[numTable][i][index1] == names[numTable][j][index2]) { + continue;//do nothing, but continue + } else //name at i is smaller than name + { + break; + } + } + } + } + } + } + + /** + * Prints row by row + * + * @param ar + */ + public static void printRowMajorOrder(char[][][] array) { + for (char[][] i : array) { + System.out.println("---------------------------------"); + printRowMajorOrder(i); + } + } + + public static void printRowMajorOrder(char[][] ar) { + for (int i = 0; i < ar.length; ++i) { + for (int j = 0; j < ar[i].length; ++j) { + System.out.print(ar[i][j]); + } + System.out.print(" "); + + } + System.out.println(); + } + + public static void main(String[] args) { + char[][] names + = { + {'j', 'o', 'h', 'n'}, {'a', 'n'}, {'b', 'y', 'r', 'o', 'n'}, + {'b', 'y', 'r', 'o', 'n', 'i'}, {'a', 'a', 'o', 'n'}, + {'b', 'b', 'b', 'b'}, {'b', 'b', 'b', 'c'}, {'b', 'b', 'b'} + }; + char[][][] tables + = { + { + { + 'j', 'o', 'h', 'n' + }, + { + 'a', 'n' + }, + { + 'b', 'y', 'r', 'o', 'n' + }, + { + 'b', 'y', 'r', 'o', 'n', 'i' + } + }, + { + { + 'a', 'a', 'o', 'n' + }, + { + 'b', 'b', 'b', 'b' + }, + { + 'b', 'b', 'b', 'c' + }, + { + 'b', 'b', 'b' + } + } + }; + System.out.println("ORIGINAL LIST"); + printRowMajorOrder(tables); + + System.out.println("\n\nSORTED LIST"); + sortNames(tables); + printRowMajorOrder(tables); + } +} diff --git a/Semester 2/Assignments/MP1_CalebFontenot/.~lock.mp1-s23-1.docx# b/Semester 2/Assignments/MP1_CalebFontenot/.~lock.mp1-s23-1.docx# deleted file mode 100644 index df1e365..0000000 --- a/Semester 2/Assignments/MP1_CalebFontenot/.~lock.mp1-s23-1.docx# +++ /dev/null @@ -1 +0,0 @@ -,caleb,caleb-ryzen-archlinux,14.01.2023 14:36,file:///home/caleb/.config/libreoffice/4; \ No newline at end of file diff --git a/Semester 2/Assignments/MP1_CalebFontenot/Lab3DArraysSort_CalebFontenot.html b/Semester 2/Assignments/MP1_CalebFontenot/Lab3DArraysSort_CalebFontenot.html new file mode 100644 index 0000000..eb030c0 --- /dev/null +++ b/Semester 2/Assignments/MP1_CalebFontenot/Lab3DArraysSort_CalebFontenot.html @@ -0,0 +1,179 @@ + + + +Lab3DArraysSort_CalebFontenot.java + + + + +
/home/caleb/ASDV-Java/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/Lab3DArraysSort_CalebFontenot.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ */
+package com.calebfontenot.mp1_calebfontenot;
+
+/**
+ *
+ * @author caleb
+ */
+public class Lab3DArraysSort_CalebFontenot {
+
+    public static int maxNumberOfColumnsInJagged2dArray(char[][] ar) {
+        int maxNumberOfColumns = 0;
+        for (int row = 0; row < ar.length; ++row) {
+            if (ar[row].length > maxNumberOfColumns) {
+                maxNumberOfColumns = ar[row].length;
+            }
+        }
+
+        return maxNumberOfColumns;
+    }
+
+    public static void printColumnMajorOrder(char[][] ar) {
+        int row = 0;
+        int column = 0;
+        int max = maxNumberOfColumnsInJagged2dArray(ar);
+        for (column = 0; column < max; ++column) {
+            for (row = 0; row < ar.length; ++row) {
+                if (column < ar[row].length) {
+                    System.out.print(ar[row][column] + " ");
+                }
+            }
+            System.out.println("");
+        }
+    }
+
+    /**
+     * Prints row by row
+     *
+     * @param ar
+     */
+    public static void printRowMajorOrder(char[][][] array) {
+        for (char[][] i: array) {
+            System.out.println("---------------------------------");
+            printRowMajorOrder(i);
+        }
+    }
+    public static void printRowMajorOrder(char[][] ar)//normal
+    {
+        for (int x = 0; x < ar.length; ++x) {
+            for (int y = 0; y < ar[x].length; ++y) {
+                System.out.print(ar[x][y] + "");
+            }
+            System.out.println();
+        }
+
+    }
+
+    public static String returnRowMajorOrder(char[] ar)//normal
+    {
+        String returnString = "";
+        for (int x = 0; x < ar.length; ++x) {
+            returnString += ar[x];
+        }
+        return returnString;
+    }
+
+    /**
+     * Sorts the methods in ascending order using Selection Sort
+     *
+     * @param names the names to be sorted
+     */
+    public static void sortNames(char[][][] names) {
+        for (int array = 0; array < names.length; ++array) {
+            System.out.println("times looped: " + array);
+            for (int i = 0; i < names[array].length - 1; ++i) {
+                for (int j = i + 1; j < names[array].length; ++j) {
+                    char compChar1 = names[array][i][0], compChar2 = names[array][j][0];
+                    // Reoder entire row
+                    for (int rowIterate = 1; rowIterate < maxNumberOfColumnsInJagged2dArray(names[array]); ++rowIterate) {
+                        if (Character.toLowerCase(compChar1) == Character.toLowerCase(compChar2)) {
+                            try {
+                                compChar1 = names[array][i][rowIterate];
+                                compChar2 = names[array][j][rowIterate];
+                            } catch (Exception ex) {
+                                // If it's failed, the index has gone out of range.
+                                // Check the length of the arrays and swap the larger one with the smaller one.
+                                if (names[array][i].length > names[array][j].length) {
+                                    System.out.println(names[array][i].length + " " + names[array][j].length);
+                                    System.out.println("Swapping " + returnRowMajorOrder(names[array][i]) + " with " + returnRowMajorOrder(names[array][j]));
+                                    char[] temp = names[array][i];
+                                    names[array][i] = names[array][j];
+                                    names[array][j] = temp;
+                                }
+                                break;
+                            }
+
+                        }
+                        if (Character.toLowerCase(compChar1) > Character.toLowerCase(compChar2)) {
+                            System.out.println("Swapping " + returnRowMajorOrder(names[array][i]) + " with " + returnRowMajorOrder(names[array][j]));
+                            char[] temp = names[array][i];
+                            names[array][i] = names[array][j];
+                            names[array][j] = temp;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) {
+        /*
+char[][] names = {
+            {'j', 'o', 'h', 'n'},
+            {'a', 'n'},
+            {'b', 'y', 'r', 'o', 'n'},};
+         */
+        ///*
+        char[][][] names = {
+            {
+                {'j', 'o', 'h', 'n'},
+                {'a', 'n'},
+                {'b', 'y', 'r', 'o', 'n'},
+                {'b', 'y', 'r', 'o', 'n', 'i'},
+                {'a', 'a', 'o', 'n'},
+                {'b', 'b', 'b', 'b'},
+                {'b', 'b', 'b', 'c'},
+                {'b', 'b', 'b'}
+            },
+            {
+                {'L', 'i', 's', 's', 'e', 't'},
+                {'E', 't', 'h', 'a', 'n'},
+                {'C', 'a', 'l', 'e', 'b'},
+                {'L', 'u', 'l', 'y'},
+                {'C', 'h', 'a', 'n', 'c', 'e'}
+            }
+        };
+//*/
+        //printColumnMajorOrder(names);
+        printRowMajorOrder(names);
+        System.out.println();
+        sortNames(names);
+        System.out.println();
+        printRowMajorOrder(names);
+        //printColumnMajorOrder(names);
+
+    }
+
+}
+
+
+ diff --git a/Semester 2/Assignments/MP1_CalebFontenot/MP1_CalebFontenot.html b/Semester 2/Assignments/MP1_CalebFontenot/MP1_CalebFontenot.html new file mode 100644 index 0000000..04469f1 --- /dev/null +++ b/Semester 2/Assignments/MP1_CalebFontenot/MP1_CalebFontenot.html @@ -0,0 +1,296 @@ + + + +MP1_CalebFontenot.java + + + + +
/home/caleb/ASDV-Java/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ */
+package com.calebfontenot.mp1_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class MP1_CalebFontenot {
+
+    public static int[][] inputArray() {
+        int m, n, i, j;
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        System.out.print("Enter the number of rows: ");
+        //taking row as input  
+        m = input.nextInt();
+        System.out.print("Enter the number of columns: ");
+        //taking column as input  
+        n = input.nextInt();
+        // Declaring the two-dimensional matrix   
+        int returnArray[][] = new int[m][n];
+        // Read the matrix values   
+        System.out.println("Enter the elements of the array: ");
+        //loop for row  
+        for (i = 0; i < m; i++) //inner for loop for column  
+        {
+            for (j = 0; j < n; j++) {
+                returnArray[i][j] = input.nextInt();
+            }
+        }
+        //accessing array elements   
+        System.out.println("Elements of the array are: ");
+        for (i = 0; i < m; i++) {
+            for (j = 0; j < n; j++) {
+                return returnArray;
+            }
+        }
+        return null;
+    }
+
+    public static boolean isConsecutiveFour(int[] values) {
+        for (int i = 0; i < values.length - 4; ++i) {
+            if (values[i] == values[i + 1]
+                    && values[i + 1] == values[i + 2]
+                    && values[i + 2] == values[i + 3]) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        return false;
+    }
+
+    public static void main(String[] args) { //2965
+        int[][] horizontalTestArray = { // Horizontal
+            {0, 1, 0, 3, 1, 6, 1},
+            {0, 1, 6, 8, 6, 0, 1},
+            {5, 6, 2, 1, 8, 2, 9},
+            {6, 5, 6, 1, 1, 9, 1},
+            {1, 3, 6, 1, 4, 0, 7},
+            {3, 3, 3, 3, 4, 0, 7}
+        };
+
+        int[][] verticalTestArray = { // Vertical
+            {0, 1, 0, 3, 1, 6, 1},
+            {0, 1, 6, 8, 6, 0, 1},
+            {5, 5, 2, 1, 8, 2, 9},
+            {6, 5, 6, 1, 1, 9, 1},
+            {1, 5, 6, 1, 4, 0, 7},
+            {3, 5, 3, 3, 4, 0, 7}
+        };
+        int[][] diagonalTestArray1 = { // Diagonal 1
+            {0, 1, 0, 3, 1, 6, 1},
+            {0, 1, 6, 8, 6, 0, 1},
+            {9, 6, 2, 1, 8, 2, 9},
+            {6, 9, 6, 1, 1, 9, 1},
+            {1, 3, 9, 1, 4, 0, 7},
+            {3, 3, 3, 9, 4, 0, 7}
+        };
+        int[][] diagonalTestArray2 = { // Diagonal 2
+            {0, 1, 0, 3, 1, 6, 1},
+            {0, 1, 6, 8, 6, 0, 1},
+            {9, 6, 2, 1, 8, 2, 9},
+            {6, 9, 6, 1, 1, 9, 1},
+            {1, 3, 9, 1, 4, 0, 7},
+            {3, 3, 3, 9, 4, 0, 7}
+        };
+
+        // Create scanner
+        Scanner input = new Scanner(System.in);
+        int userInput;
+        do {
+            System.out.println("Do you want to enter an array, or use a predefined one?");
+            System.out.println("1. Use predefined array.");
+            System.out.println("2. Enter a new array.");
+            System.out.println("-1. quit and exit program");
+            System.out.print("Input: ");
+            userInput = input.nextInt();
+            if (userInput == 1) {
+                System.out.println("Selected \"Use predefined array\"");
+                System.out.println("Printing arrays...");
+                System.out.println("1. horizontalTestArray");
+                printArray(horizontalTestArray);
+                System.out.println("2. verticalTestArray");
+                printArray(verticalTestArray);
+                System.out.println("3. diagonalTestArray1");
+                printArray(diagonalTestArray1);
+                System.out.println("4. diagonalTestArray2");
+                printArray(diagonalTestArray2);
+                System.out.print("Input: ");
+                userInput = input.nextInt();
+                if (userInput == 1) {
+                    if (isConsecutiveFour(horizontalTestArray)) {
+                        System.out.println("Testing method returns true");
+                    } else {
+                        System.out.println("Testing method returns false");
+                    }
+                }
+                if (userInput == 2) {
+                    if (isConsecutiveFour(verticalTestArray)) {
+                        System.out.println("Testing method returns true");
+                    } else {
+                        System.out.println("Testing method returns false");
+                    }
+                }
+                if (userInput == 3) {
+                    if (isConsecutiveFour(diagonalTestArray1)) {
+                        System.out.println("Testing method returns true");
+                    } else {
+                        System.out.println("Testing method returns false");
+                    }
+                }
+                if (userInput == 4) {
+                    if (isConsecutiveFour(diagonalTestArray2)) {
+                        System.out.println("Testing method returns true");
+                    } else {
+                        System.out.println("Testing method returns false");
+                    }
+                }
+                userInput = 0;
+            }
+            if (userInput == 2) {
+                System.out.println("Selected \"Enter new array\"");
+                int[][] newArray = inputArray();
+                if (isConsecutiveFour(newArray)) {
+                    System.out.println("Testing method returns true");
+                } else {
+                    System.out.println("Testing method returns false");
+                }
+            }
+        } while (userInput != -1);
+        System.exit(0);
+        //printArray(intArray1);
+        //System.out.println(isConsecutiveFour(intArray1));
+    }
+
+    public static void printArray(int[][] array) {
+        int rowCounter = 0;
+        for (int x = 0; x < array.length; x++) {
+            for (int y = 0; y < array[x].length; y++) {
+                System.out.print(array[x][y] + " ");
+                rowCounter++;
+                if (rowCounter % (array.length + 1) == 0) {
+                    System.out.println();
+                }
+            }
+        }
+    }
+
+    public static void printArray(int[] array) {
+        for (int i : array) {
+            System.out.print(i + " ");
+        }
+    }
+
+    public static boolean isConsecutiveFour(int[][] values) {
+        // Horizontal Checking
+        System.out.println("Checking for Horizontal matches...");
+        boolean horizontalTest = horizontalMatch(values);
+        // Vertical Checking
+        System.out.println("Checking for Vertical matches...");
+        boolean verticalTest = verticalMatch(values);
+        System.out.println("Checking for Diagonal matches...");
+        boolean diagonalTest = diagonalMatch(values);
+        if (horizontalTest || verticalTest || diagonalTest) {
+            System.out.println("Match found!");
+            return true;
+        }
+        System.out.println("No match found.");
+        return false;
+    }
+
+    public static boolean diagonalMatch(int[][] array) {
+        for (int row = 0; row < array.length - 3; row++) {
+            for (int col = 0; col < array[row].length - 3; col++) {
+                // Check for four consecutive numbers diagonally from top-left to bottom-right
+                if (array[row][col] == array[row + 1][col + 1] && array[row + 1][col + 1] == array[row + 2][col + 2]
+                        && array[row + 2][col + 2] == array[row + 3][col + 3]) {
+                    System.out.println("Found four consecutive numbers diagonally at: " + row + "," + col);
+                    return true;
+                }
+                // Check for four consecutive numbers diagonally from top-right to bottom-left
+                if (array[row][col + 3] == array[row + 1][col + 2] && array[row + 1][col + 2] == array[row + 2][col + 1]
+                        && array[row + 2][col + 1] == array[row + 3][col]) {
+                    System.out.println("Found four consecutive numbers diagonally at: " + row + "," + (col + 3));
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public static boolean verticalMatch(int[][] values) {
+        int intCounter = 0, y = 0;
+        for (int rowIterate = 0; rowIterate < values.length; ++rowIterate) {
+            y = 0;
+            for (int x = 0; x < values.length - 1; ++x) {
+                ++y;
+                if (values[x][rowIterate] == values[y][rowIterate]) {
+                    intCounter++;
+                    System.out.println(values[x][rowIterate] + " " + values[y][rowIterate] + ",  intCounter: " + intCounter);
+                } else {
+                    intCounter = 0;
+                    System.out.println(values[x][rowIterate] + " " + values[y][rowIterate] + ",  intCounter: " + intCounter);
+                }
+                if (intCounter == 3) {
+                    System.out.println("Vertical match!");
+                    return true;
+                }
+            }
+            System.out.println("Checking next line...");
+        }
+        return false;
+    }
+
+    public static boolean horizontalMatch(int[][] values) {
+        int intCounter = 0, y = 0;
+        // Horizontal checking
+        // If the same value has been observed 4 times, return true
+        //System.out.println("values[0].length: " + values[0].length);
+        //System.out.println("values.length: " + values.length);
+
+        for (int rowIterate = 0; rowIterate < values.length; ++rowIterate) {
+            y = 0;
+            for (int x = 0; x < values[0].length - 1; ++x) {
+                ++y;
+                if (values[rowIterate][x] == values[rowIterate][y]) {
+                    intCounter++;
+                    System.out.println(values[rowIterate][x] + " " + values[rowIterate][y] + ",  intCounter: " + intCounter);
+                } else {
+                    intCounter = 0;
+                    System.out.println(values[rowIterate][x] + " " + values[rowIterate][y] + ",  intCounter: " + intCounter);
+                }
+                if (intCounter == 3) {
+                    System.out.println("Horizontal match!");
+                    return true;
+                }
+            }
+            System.out.println("Checking next line...");
+        }
+        return false;
+    }
+}
+
+
+ diff --git a/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java b/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java index 485de87..39c38ee 100644 --- a/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java +++ b/Semester 2/Assignments/MP1_CalebFontenot/src/main/java/com/calebfontenot/mp1_calebfontenot/MP1_CalebFontenot.java @@ -73,7 +73,7 @@ public class MP1_CalebFontenot { {1, 5, 6, 1, 4, 0, 7}, {3, 5, 3, 3, 4, 0, 7} }; - int[][] diagonalTestArray = { // Diagonal 1 + int[][] diagonalTestArray1 = { // Diagonal 1 {0, 1, 0, 3, 1, 6, 1}, {0, 1, 6, 8, 6, 0, 1}, {9, 6, 2, 1, 8, 2, 9}, @@ -81,6 +81,15 @@ public class MP1_CalebFontenot { {1, 3, 9, 1, 4, 0, 7}, {3, 3, 3, 9, 4, 0, 7} }; + int[][] diagonalTestArray2 = { // Diagonal 2 + {0, 1, 0, 3, 1, 6, 1}, + {0, 1, 6, 8, 6, 0, 1}, + {9, 6, 2, 1, 8, 2, 9}, + {6, 9, 6, 1, 1, 9, 1}, + {1, 3, 9, 1, 4, 0, 7}, + {3, 3, 3, 9, 4, 0, 7} + }; + // Create scanner Scanner input = new Scanner(System.in); int userInput; @@ -98,8 +107,10 @@ public class MP1_CalebFontenot { printArray(horizontalTestArray); System.out.println("2. verticalTestArray"); printArray(verticalTestArray); - System.out.println("3. diagonalTestArray"); - printArray(diagonalTestArray); + System.out.println("3. diagonalTestArray1"); + printArray(diagonalTestArray1); + System.out.println("4. diagonalTestArray2"); + printArray(diagonalTestArray2); System.out.print("Input: "); userInput = input.nextInt(); if (userInput == 1) { @@ -117,7 +128,14 @@ public class MP1_CalebFontenot { } } if (userInput == 3) { - if (isConsecutiveFour(diagonalTestArray)) { + if (isConsecutiveFour(diagonalTestArray1)) { + System.out.println("Testing method returns true"); + } else { + System.out.println("Testing method returns false"); + } + } + if (userInput == 4) { + if (isConsecutiveFour(diagonalTestArray2)) { System.out.println("Testing method returns true"); } else { System.out.println("Testing method returns false"); @@ -167,10 +185,8 @@ public class MP1_CalebFontenot { System.out.println("Checking for Vertical matches..."); boolean verticalTest = verticalMatch(values); System.out.println("Checking for Diagonal matches..."); - boolean diagonalNorthwest = MarkouCode.topLeftTriangleDiagonalNothwest(values); - boolean diagonalMiddle = MarkouCode.bottomRightTriangleDiagonalNothwest(values); - System.out.println(diagonalNorthwest); - if (horizontalTest || verticalTest || diagonalNorthwest) { + boolean diagonalTest = diagonalMatch(values); + if (horizontalTest || verticalTest || diagonalTest) { System.out.println("Match found!"); return true; } @@ -178,6 +194,26 @@ public class MP1_CalebFontenot { return false; } + public static boolean diagonalMatch(int[][] array) { + for (int row = 0; row < array.length - 3; row++) { + for (int col = 0; col < array[row].length - 3; col++) { + // Check for four consecutive numbers diagonally from top-left to bottom-right + if (array[row][col] == array[row + 1][col + 1] && array[row + 1][col + 1] == array[row + 2][col + 2] + && array[row + 2][col + 2] == array[row + 3][col + 3]) { + System.out.println("Found four consecutive numbers diagonally at: " + row + "," + col); + return true; + } + // Check for four consecutive numbers diagonally from top-right to bottom-left + if (array[row][col + 3] == array[row + 1][col + 2] && array[row + 1][col + 2] == array[row + 2][col + 1] + && array[row + 2][col + 1] == array[row + 3][col]) { + System.out.println("Found four consecutive numbers diagonally at: " + row + "," + (col + 3)); + return true; + } + } + } + return false; + } + public static boolean verticalMatch(int[][] values) { int intCounter = 0, y = 0; for (int rowIterate = 0; rowIterate < values.length; ++rowIterate) { @@ -200,8 +236,9 @@ public class MP1_CalebFontenot { } return false; } + public static boolean horizontalMatch(int[][] values) { - int intCounter = 0, y = 0; + int intCounter = 0, y = 0; // Horizontal checking // If the same value has been observed 4 times, return true //System.out.println("values[0].length: " + values[0].length); diff --git a/Semester 2/ZIPs/MP1_CalebFontenot.zip b/Semester 2/ZIPs/MP1_CalebFontenot.zip new file mode 100644 index 0000000..93dcf19 Binary files /dev/null and b/Semester 2/ZIPs/MP1_CalebFontenot.zip differ