Word search puzzle 👀
This commit is contained in:
parent
3df7388a4b
commit
87e04d639d
1
.gitignore
vendored
1
.gitignore
vendored
@ -97,3 +97,4 @@
|
||||
/Semester 2/Assignments/lab-2D-arrays_CalebFontenot/target/
|
||||
/Semester 2/Assignments/lab-2D-arrays-sort_CalebFontenot/target/
|
||||
/Semester 2/Assignments/lab3_CalebFontenot/target/
|
||||
/Semester 2/Assignments/MP1_CalebFontenot/target/
|
||||
|
@ -0,0 +1 @@
|
||||
,caleb,caleb-gaming-laptop-archlinux,13.01.2023 10:13,file:///home/caleb/.config/libreoffice/4;
|
@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.calebfontenot.mp1_calebfontenot;
|
||||
|
||||
/**
|
||||
@ -10,7 +9,119 @@ package com.calebfontenot.mp1_calebfontenot;
|
||||
*/
|
||||
public class MP1_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
public static void main(String[] args)
|
||||
{ //2965
|
||||
/*
|
||||
int[][] intArray = { // 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[][] intArray = { // 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[][] intArray = { // 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}
|
||||
};
|
||||
printArray(intArray);
|
||||
System.out.println(isConsecutiveFour(intArray));
|
||||
}
|
||||
|
||||
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 boolean isConsecutiveFour(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);
|
||||
System.out.println("Checking for Horizontal matches...");
|
||||
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...");
|
||||
}
|
||||
// Vertical Checking
|
||||
System.out.println("Checking for Vertical matches...");
|
||||
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...");
|
||||
}
|
||||
System.out.println("Checking for Diagonal matches...");
|
||||
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 + 1][y + 1]) {
|
||||
intCounter++;
|
||||
System.out.println(values[rowIterate][x] + " " + values[rowIterate + 1][y ] + ", intCounter: " + intCounter);
|
||||
} else {
|
||||
intCounter = 0;
|
||||
System.out.println(values[rowIterate][x] + " " + values[rowIterate + 1][y] + ", intCounter: " + intCounter);
|
||||
}
|
||||
if (intCounter == 3) {
|
||||
System.out.println("Diagonal match!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
System.out.println("Checking next line...");
|
||||
}
|
||||
System.out.println("No match found.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user