Updated documentation

This commit is contained in:
2024-01-07 19:36:21 -05:00
parent efc2c55e21
commit 646027ee1d
11 changed files with 104 additions and 59 deletions

72
src/S1.java Normal file
View File

@ -0,0 +1,72 @@
package src;// Zak Timson
// Libraries
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
// Class
public class S1 {
// Main method
public static void main(String[] args) throws FileNotFoundException {
// Because numbers will be removed each pass
// A dynamic array might be nice
ArrayList list = new ArrayList();
// Import dummy data from src.S1.txt
final String dir = new File(" ").getAbsolutePath().trim();
FileReader fr = new FileReader(dir + "S1.txt");
Scanner scan = new Scanner(fr);
int k = scan.nextInt();
// Fill array with required number of people
for (int i = 0; i < k; i++) {
list.add(String.valueOf(i + 1));
}
// Create an array for the different number of passes
// that will be done
int m = scan.nextInt();
int[] remove = new int[m];
for (int i = 0; i < m; i++) {
remove[i] = scan.nextInt();
}
// Loop through each pass
for (int i = 0; i < m; i++) {
// Remember the size of the dynamic array during this pass
int size = list.size();
// Instead of looping through and testing each number in the array
// some preliminary math can determine the exact number of passes
// needed to increase the efficiency.
for (int x = 0; x < size / remove[i]; x++) {
/* This next part is where a quarter of the competition went well
* I over thought how to solve this bug. Because I am removing,
* lets say person 5 and 10, as soon as I remove person 5 person 10
* will no longer be in index number 9 but rather 8 as it is shrinking.
* After thinking about this for quite some time I decided best to move on
* and do problem number 2. After completing that one I cam back and instantly
* came up with the idea of filling that space with a String object == "".
*/
list.remove(((x + 1) * remove[i]) - 1);
list.add((x + 1) * remove[i] - 1, "");
}
// Once every person that needed to be removed is switched for a ""
// all objects == "" are removed getting rid of that bug.
while (list.indexOf("") != -1) {
list.remove(list.indexOf(""));
}
}
// Output the remainder of the dynamic array
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}

57
src/S2.java Normal file
View File

@ -0,0 +1,57 @@
package src;// Zak Timson
// Libraries
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
//Class
public class S2 {
// Main method
public static void main(String[] args) throws FileNotFoundException {
// Load in dummy data from file
final String dir = new File(" ").getAbsolutePath().trim();
FileReader fr = new FileReader(dir + "S2.txt");
Scanner scan = new Scanner(fr);
// Get the number of names (never used this information)
String n = scan.nextLine();
// Get the names from file and split the line into an array by white space
String names1 = scan.nextLine();
String[] nameSet1 = names1.split(" ");
// Same as above for second set of names.
String names2 = scan.nextLine();
String[] nameSet2 = names2.split(" ");
// Flags
boolean flag = true;
int counter = 0;
try {
while (flag) {
// Compare names index by index
if (nameSet1[counter].equals(nameSet2[counter])) {
flag = false; // if two of the same names are found
// Stop the program because it failed
}
counter++;
// Counter to keep track of index
// As soon as counter > nameSet1.length it will create an
// Index out of bounds error (This allows the flag to stay true)
}
}catch(Exception e){}
// Based on whether the program errors out or switches the flag a verdict
// can be found
if (flag) {
System.out.println("good");
} else {
System.out.println("bad");
}
}
}

80
src/S3.java Normal file
View File

@ -0,0 +1,80 @@
package src;// Zak Timson
// Libraries
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
// Class
public class S3 {
// Main method
public static void main(String[] args) throws FileNotFoundException {
// Load dummy data
final String dir = new File(" ").getAbsolutePath().trim();
FileReader fr = new FileReader(dir + "S3.txt");
Scanner scan = new Scanner(fr);
// Get number of tests
int tests = scan.nextInt();
// Create 2D array to hold all of the information
int[][] cars = new int[tests][];
for (int i = 0; i < tests; i++) {
int num = scan.nextInt(); // get number of cars in test
cars[i] = new int[num]; // initiate
// Load cars into array
for (int x = 0; x < num; x++) {
cars[i][x] = scan.nextInt();
}
}
// Loop until every test is complete
for (int i = 0; i < cars.length; i++) {
// Create two dynamic arrays for the train track and branch track by the lake
ArrayList train = new ArrayList();
ArrayList branch = new ArrayList();
// Add all the cars to the track
for (int x = (cars[i].length-1); x >= 0; x--) {
train.add(cars[i][x]);
}
boolean flag = true;
int counter = 1; // If there is only one train left it can be completed so offset of 1 is needed to make if's bellow work
// Not error checking for consecutive numbers ex. 1, 2, 5, 3. car 4 is missed.
// Loop until flag changes
while (flag) {
// If first car on track is required car
if (Integer.parseInt(train.get(0).toString()) == counter){
counter++; // Update what car is next required
train.remove(0); // remove that car from first position on track
} else { // Else move first car onto branch
branch.add(0, train.get(0).toString());
train.remove(0);
}
// Check fist car on branch to see if it is the required car
if (Integer.parseInt(branch.get(0).toString()) == counter){
counter++; // Update counter
branch.remove(0); // Remove it
}
// If there is only 1 car left it is a success
if (counter == cars[i].length){
flag = false; // Make loop stop
System.out.println("Y"); // Output result
// If there is nothing left on the main track and the first car on the branch track is
// not the required car the test is a failure
} else if (train.size() == 0 && Integer.parseInt(branch.get(0).toString()) != counter){
flag = false; // Stop loop
System.out.println("N"); // Output result
}
}
}
}
}

68
src/S4.java Normal file
View File

@ -0,0 +1,68 @@
package src;// Zak Timson
// Uses Tint.java (Object)
/* I didn't finish this program because I got stuck up on the first program trying to fix a bug so I ran out of time.
My thinking behind this problem was making an object for each stain glass piece so I could send the object a
location and have it return true or false. and from that I could run that each coordinate through two for loops of
the largest x and y and determine whether each point was the right tint level. This is as far as I got but after that
I was planning on using this data to make a graph similar to the example given and from that I could make the program
realise that point (1,2) and (2,2) are part of the same area. This program does have an error so it doesn't run from what
I gather because I ran it for the first time just as the competition ended.
*/
// Libraries
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
// Class
public class S4 {
// Main method
public static void main(String[] args) throws FileNotFoundException {
// Load dummy data
final String dir = new File(" ").getAbsolutePath().trim();
FileReader fr = new FileReader(dir + "S4.txt");
Scanner scan = new Scanner(fr);
// Load number of pieces
int pcs = scan.nextInt();
// Load what shade of tint we are looking for
int lookFor = scan.nextInt();
int counter = 0; // keep track of matches
// create an array of the pieces of tint glass using my Tint object
Tint[] tint = new Tint[pcs];
// Loop for each piece of tinted glass
for (int i = 0; i < tint.length; i++) {
String temp = scan.nextLine(); // Get the next line of coordinates
String[] stats = temp.split(" "); // Split the coordinates
// Create a new Tint object with the coordinates
tint[i] = new Tint(Integer.parseInt(stats[0]),
Integer.parseInt(stats[1]), Integer.parseInt(stats[2]),
Integer.parseInt(stats[3]), Integer.parseInt(stats[4]));
}
// Loop through coordinates
for (int x = 0; x < 1000000000; x++){ // X coordinate
int totalTint = 0; // Reset the total tint on this coordinate
for (int y = 0; y < 1000000000; y++){ // Y coordinate
// Test to see if each piece of glass to see if coordinate is present in its area
for (int i = 0; i < tint.length; i++){
// if it is get the tint and add it to the total tint of that coordinate
if (tint[i].within(x, y) == true){
totalTint+=tint[i].getTint();
}
// If the total tint is = to what is being looked for
if (totalTint == lookFor){
counter++;
}
}
}
}
System.out.println(counter); // Output the number of tinted spots
}
}