commit d6e568c68566fcb9b40aed67179e14da25b47ac2 Author: ztimson Date: Mon Aug 5 20:22:36 2019 -0400 init diff --git a/Read Me.txt b/Read Me.txt new file mode 100644 index 0000000..54d58f6 --- /dev/null +++ b/Read Me.txt @@ -0,0 +1,17 @@ +Here are my competition programs, I completed 3/5 (+an unworking program that I didnt have time for (#4)) +All my programs are unmodified sense I originaly codded them so you can see my raw coding skill well working fast and underpressure. The only +things I added was the comment to walk you through my thought prosses + +Summary of rules: + - Only writen resorces are allowed to be brought in and used + - Every file must use file input and standard output (Names correspond (S1.java < S1.txt)) + - 3 hours to complete as many as possible + only completed programs count + - some programs may be rated on efficency + +Notes: + - I doubled the second place person's score in the local area. + +UPDATE: + - My first two programs recieved full marks and completed every test + - My third failed misserably and because I needed a minimum of 40 points (15 points a question) + I could not move on to participate at waterloo \ No newline at end of file diff --git a/S1.java b/S1.java new file mode 100644 index 0000000..b9f649a --- /dev/null +++ b/S1.java @@ -0,0 +1,72 @@ +// 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 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)); + } + } +} diff --git a/S1.txt b/S1.txt new file mode 100644 index 0000000..d6db3ff --- /dev/null +++ b/S1.txt @@ -0,0 +1,4 @@ +10 +2 +2 +3 \ No newline at end of file diff --git a/S2.java b/S2.java new file mode 100644 index 0000000..4f80ef6 --- /dev/null +++ b/S2.java @@ -0,0 +1,57 @@ +// 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"); + } + } +} diff --git a/S2.txt b/S2.txt new file mode 100644 index 0000000..2a4a309 --- /dev/null +++ b/S2.txt @@ -0,0 +1,3 @@ +4 +Ada Alan Grace John +John Grace Alan Ada \ No newline at end of file diff --git a/S3.java b/S3.java new file mode 100644 index 0000000..7bfc9b1 --- /dev/null +++ b/S3.java @@ -0,0 +1,80 @@ +// 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 + } + } + } + } +} diff --git a/S3.txt b/S3.txt new file mode 100644 index 0000000..c1f02dd --- /dev/null +++ b/S3.txt @@ -0,0 +1,11 @@ +2 +4 +2 +3 +1 +4 +4 +4 +1 +3 +2 \ No newline at end of file diff --git a/S4.java b/S4.java new file mode 100644 index 0000000..ce1f0e3 --- /dev/null +++ b/S4.java @@ -0,0 +1,68 @@ +// 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 + } +} diff --git a/S4.txt b/S4.txt new file mode 100644 index 0000000..c843abf --- /dev/null +++ b/S4.txt @@ -0,0 +1,6 @@ +4 +3 +11 11 20 15 1 +13 8 14 17 2 +17 8 18 17 1 +12 12 19 13 1 \ No newline at end of file diff --git a/Tint.java b/Tint.java new file mode 100644 index 0000000..69d21fc --- /dev/null +++ b/Tint.java @@ -0,0 +1,31 @@ +// Class +public class Tint { + + // Fields + double x1, x2, y1, y2; + int tint; + + // Constructor + public Tint(int x1, int y1, int x2, int y2, int tint) { + this.x1 = x1; + this.x2 = x2; + this.y1 = y1; + this.y2 = y2; + this.tint = tint; + } + + // helper to see if coordinate is within bounds of object + public boolean within(double x, double y) { + boolean flag = false; + + if (x > this.x1 && x < this.x2 && y > this.y1 && y < this.y2) + flag = true; + + return flag; + } + + // Accessor + public int getTint() { + return this.tint; + } +} diff --git a/seniorEn.pdf b/seniorEn.pdf new file mode 100644 index 0000000..f77888b Binary files /dev/null and b/seniorEn.pdf differ