diff --git a/uil/october-2013/10/10/.classpath b/uil/october-2013/10/10/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/uil/october-2013/10/10/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/uil/october-2013/10/10/.project b/uil/october-2013/10/10/.project new file mode 100644 index 0000000..a3e3a53 --- /dev/null +++ b/uil/october-2013/10/10/.project @@ -0,0 +1,17 @@ + + + 10 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/uil/october-2013/10/10/.settings/org.eclipse.jdt.core.prefs b/uil/october-2013/10/10/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/uil/october-2013/10/10/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/uil/october-2013/10/10/.vscode/launch.json b/uil/october-2013/10/10/.vscode/launch.json new file mode 100644 index 0000000..73488eb --- /dev/null +++ b/uil/october-2013/10/10/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "configurations": [ + { + "type": "java", + "name": "CodeLens (Launch) - problem10", + "request": "launch", + "mainClass": "problem10", + "projectName": "10" + } + ] +} \ No newline at end of file diff --git a/uil/october-2013/10/10/bin/Synonym.class b/uil/october-2013/10/10/bin/Synonym.class new file mode 100644 index 0000000..bb4d8b9 Binary files /dev/null and b/uil/october-2013/10/10/bin/Synonym.class differ diff --git a/uil/october-2013/10/10/bin/SynonymOrganizer.class b/uil/october-2013/10/10/bin/SynonymOrganizer.class new file mode 100644 index 0000000..711d410 Binary files /dev/null and b/uil/october-2013/10/10/bin/SynonymOrganizer.class differ diff --git a/uil/october-2013/10/10/bin/problem10.class b/uil/october-2013/10/10/bin/problem10.class new file mode 100644 index 0000000..3cefaaf Binary files /dev/null and b/uil/october-2013/10/10/bin/problem10.class differ diff --git a/uil/october-2013/10/10/input.dat b/uil/october-2013/10/10/input.dat new file mode 100644 index 0000000..a28a893 --- /dev/null +++ b/uil/october-2013/10/10/input.dat @@ -0,0 +1,10 @@ +4 +this paragraph was fun to write i love to write fun assignments +having work to do is very fun my favorite subject is english but +i also love to write programs which is a close second but not +bad this bad assignment was bad bad bad bad and bad +4 +fun diverting festive +love enjoy relish +write scribe code +bad horrible bitter terrible evil base rancid \ No newline at end of file diff --git a/uil/october-2013/10/10/src/problem10.java b/uil/october-2013/10/10/src/problem10.java new file mode 100644 index 0000000..88f043e --- /dev/null +++ b/uil/october-2013/10/10/src/problem10.java @@ -0,0 +1,94 @@ +import static java.lang.System.*; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +class Synonym { + int index = 0; + List synonyms; + Synonym(String[] synonyms) { + this.synonyms = Arrays.asList(synonyms); + } + + String next() { + return synonyms.get(this.index++ % synonyms.size()); + } +} + + +class SynonymOrganizer { + Map points = new HashMap(); + List synonyms = new ArrayList(); + + // Takes lines of synonyms + SynonymOrganizer(String[] synlines) { + int creationIndex = 0; + // Iterate over each line and process synonyms + for(String line : synlines) { + // Get all words in synonym list + String[] words = line.split("\\s"); + for(String word : words) { + // Can switch off to using Map> for multi-value synonyms instead of singular + if(points.containsKey(word)) + out.println("Word \"" + word + "\" already used for previous synonym, overwriting."); + points.put(word, creationIndex); + } + // Add the list of synonyms with new Synonym object + synonyms.add(new Synonym(words)); + // Increment for next pointer + creationIndex++; + } + } + + boolean hasSynonym(String word) { + return points.containsKey(word); + } + + // Gets a synonym, increments synonym object index + String getSynonym(String word) { + // Pointless in a perfect world + if(!points.containsKey(word)) { + out.println("Word\"" + word + "\"had no synonyms!"); + } + // Retriever integer map pointer, then return next synonym + int pointer = points.get(word); + return synonyms.get(pointer).next(); + } +} + +public class problem10 { + public static void main(String[] args) throws FileNotFoundException { + // Initial Constants + File input = new File("input.dat"); + Scanner read = new Scanner(input); + + // Read paragraph lines + String[] rawParagraph = new String[Integer.parseInt(read.nextLine())]; + for(int i = 0; i < rawParagraph.length; i++) + rawParagraph[i] = read.nextLine(); + + // Read synonym lines + String[] synonymLines = new String[Integer.parseInt(read.nextLine())]; + for(int i = 0; i < synonymLines.length; i++) + synonymLines[i] = read.nextLine(); + + // Start processing the paragraph + SynonymOrganizer organizer = new SynonymOrganizer(synonymLines); + for(String line : rawParagraph) { + String[] words = line.split("\\s"); + for(int i = 0; i < words.length; i++) { + // Replace if organizer has a synonym + if(organizer.hasSynonym(words[i])) { + words[i] = organizer.getSynonym(words[i]); + } + } + out.println(String.join(" ", words)); + } + read.close(); + } +} diff --git a/uil/october-2013/11/.vscode/launch.json b/uil/october-2013/11/.vscode/launch.json new file mode 100644 index 0000000..ef6c5d0 --- /dev/null +++ b/uil/october-2013/11/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "CodeLens (Launch) - problem11", + "request": "launch", + "mainClass": "problem11" + }, + { + "type": "java", + "name": "CodeLens (Launch) - problem9", + "request": "launch", + "mainClass": "problem9" + }, + { + "type": "java", + "name": "Debug (Launch) - Current File", + "request": "launch", + "mainClass": "${file}" + } + ] +} \ No newline at end of file diff --git a/uil/october-2013/11/input.dat b/uil/october-2013/11/input.dat new file mode 100644 index 0000000..5f5fbe7 --- /dev/null +++ b/uil/october-2013/11/input.dat @@ -0,0 +1,3 @@ +1 +2 +3 \ No newline at end of file diff --git a/uil/october-2013/11/out/production/11/problem11.class b/uil/october-2013/11/out/production/11/problem11.class new file mode 100644 index 0000000..2e52de7 Binary files /dev/null and b/uil/october-2013/11/out/production/11/problem11.class differ diff --git a/uil/october-2013/11/src/problem11.java b/uil/october-2013/11/src/problem11.java new file mode 100644 index 0000000..c715c30 --- /dev/null +++ b/uil/october-2013/11/src/problem11.java @@ -0,0 +1,14 @@ +import static java.lang.System.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class problem11 { + public static void main(String[] args) throws FileNotFoundException { + File input = new File("input.dat"); + Scanner read = new Scanner(input); + while(read.hasNextInt()) + out.println(read.nextInt() * 3); + read.close(); + } +} \ No newline at end of file diff --git a/uil/october-2013/12/.classpath b/uil/october-2013/12/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/uil/october-2013/12/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/uil/october-2013/12/.project b/uil/october-2013/12/.project new file mode 100644 index 0000000..b50b807 --- /dev/null +++ b/uil/october-2013/12/.project @@ -0,0 +1,17 @@ + + + 12 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/uil/october-2013/12/.settings/org.eclipse.jdt.core.prefs b/uil/october-2013/12/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/uil/october-2013/12/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/uil/october-2013/12/.vscode/launch.json b/uil/october-2013/12/.vscode/launch.json new file mode 100644 index 0000000..1dfdcba --- /dev/null +++ b/uil/october-2013/12/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "configurations": [ + { + "type": "java", + "name": "CodeLens (Launch) - problem12", + "request": "launch", + "mainClass": "problem12", + "projectName": "12" + } + ] +} \ No newline at end of file diff --git a/uil/october-2013/12/bin/CheckerBoard.class b/uil/october-2013/12/bin/CheckerBoard.class new file mode 100644 index 0000000..e0336f3 Binary files /dev/null and b/uil/october-2013/12/bin/CheckerBoard.class differ diff --git a/uil/october-2013/12/bin/Point.class b/uil/october-2013/12/bin/Point.class new file mode 100644 index 0000000..1ffdf68 Binary files /dev/null and b/uil/october-2013/12/bin/Point.class differ diff --git a/uil/october-2013/12/bin/problem12.class b/uil/october-2013/12/bin/problem12.class new file mode 100644 index 0000000..6b98887 Binary files /dev/null and b/uil/october-2013/12/bin/problem12.class differ diff --git a/uil/october-2013/12/input.dat b/uil/october-2013/12/input.dat new file mode 100644 index 0000000..4ed0810 --- /dev/null +++ b/uil/october-2013/12/input.dat @@ -0,0 +1,9 @@ +1 + B B + B B B +B B B + B B +B B R + R R R R +R R R R + R R R \ No newline at end of file diff --git a/uil/october-2013/12/src/problem12.java b/uil/october-2013/12/src/problem12.java new file mode 100644 index 0000000..f98ece6 --- /dev/null +++ b/uil/october-2013/12/src/problem12.java @@ -0,0 +1,52 @@ +import static java.lang.System.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Scanner; + +class Point { + int x; + int y; + Point(int x, int y) { + this.x = x; + this.y = y; + } +} + +class CheckerBoard { + Point[] offsets = {Point(1, 1), Point(-1, -1), Point(-1, 1), Point(1, -1)}; + + CheckerBoard(String[][] matrix) { + + } + + int[][] getPossible(int x, int y) { + return getPossible(x, y, new int[0][0]); + } + int[][] getPossible(int x, int y, List blacklist) {} +} + +class problem12 { + public static void main(String[] args) throws FileNotFoundException { + // Constants + File input = new File("input.dat"); + Scanner read = new Scanner(input); + int lines = Integer.parseInt(read.nextLine()); + + // Start reading and processing the matrix into + for(int i = 0; i < lines; i++) { + String[][] rawMatrix = new String[8][8]; + for(int x = 0; x < 8; x++) { + String line = read.nextLine(); + for(int y = 0; y < 8; y++) + rawMatrix[x][y] = line.substring(y, y+1); + } + + out.println(Arrays.deepToString(rawMatrix)); + CheckerBoard cb = new CheckerBoard(rawMatrix); + out.println(cb.scan()); + } + + read.close(); + } +} \ No newline at end of file diff --git a/uil/october-2013/3/java/.vscode/launch.json b/uil/october-2013/3/java/.vscode/launch.json new file mode 100644 index 0000000..cb957fb --- /dev/null +++ b/uil/october-2013/3/java/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + "configurations": [ + { + "type": "java", + "name": "CodeLens (Launch) - problem3", + "request": "launch", + "mainClass": "problem3" + } + ] +} \ No newline at end of file diff --git a/uil/october-2013/3/java/input.dat b/uil/october-2013/3/java/input.dat new file mode 100644 index 0000000..e44cf9f --- /dev/null +++ b/uil/october-2013/3/java/input.dat @@ -0,0 +1,20 @@ + + F + F + + F + + + + + XXX + + + + F + F + +UUUUULL +UULULUL +UUUUUURUULL +DRDRDD \ No newline at end of file diff --git a/uil/october-2013/3/java/src/problem3.java b/uil/october-2013/3/java/src/problem3.java index 9307636..6a3c6d1 100644 --- a/uil/october-2013/3/java/src/problem3.java +++ b/uil/october-2013/3/java/src/problem3.java @@ -2,18 +2,90 @@ import static java.lang.System.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; +import java.util.Set; +import java.util.ArrayList; + +class Point { + int x; + int y; + Point(int x, int y) { + this.x = x; + this.y = y; + } +} + +class Maze { + int[][] offsets = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; + String[][] rawMatrix; + Set snake; + Set pellets; + + Maze(String[][] rawMatrix) { + this.rawMatrix = rawMatrix; + snake = new ArrayList(); + + for(int x = 0; x < 15; x++) { + for(int y = 0; y < 15; y++) { + switch(rawMatrix[x][y]) { + case " ": + break; + case "X": + snake.add(new Point(x, y)); + break; + case "F": + pellets.add(new Point(x, y)); + break; + default: + out.println("Possibly faulty Maze Input with item \"" + rawMatrix[x][y] + "\" found."); + break; + } + } + } + } + + // Simulate the snake game using instructions + String simulate(String input) { + return ""; + } + + boolean inBounds(int x, int y) { + return x >= 0 && y >= 0 && x < 15 && y < 15; + } + + // Prints a string representation of the Maze + String toString() { + String[] lines = new String[15]; + for(int x = 0; x < 15; x++) { + String[] temp = ""; + for(int y = 0; y < 15; y++) { + temp[y] = rawMatrix[x][y]; + } + lines[x] = String.join(" - ", temp); + } + return String.join("\n", lines); + } +} public class problem3 { public static void main(String[] args ) throws FileNotFoundException { // Constants - File input = new File("input1.dat"); + File input = new File("input.dat"); Scanner read = new Scanner(input); - int lines = read.nextInt(); - read.nextLine(); - - // Driver Code - for (int i = 0; i < lines; i++) - out.println(read.nextLine().length() <= 140 ? "tweet" : "not a tweet"); + + // Read the maze into a String matrix + char[][] rawMatrix = new String[15][15]; + for(int x = 0; x < 15; x++) { + String line = read.nextLine(); + for(int y = 0; y < 15; y++) { + rawMatrix[x][y] = line.charAt(y); + } + } + + // Read each of the inputs and process inside the maze + int lines = Integer.parseInt(read.nextLine()); + String[] inputs = new String[lines]; + for(int i = 0; i < lines; i++) + inputs[i] = read.nextLine(); } } \ No newline at end of file diff --git a/uil/october-2013/9/.idea/workspace.xml b/uil/october-2013/9/.idea/workspace.xml index 77257f2..be4612b 100644 --- a/uil/october-2013/9/.idea/workspace.xml +++ b/uil/october-2013/9/.idea/workspace.xml @@ -18,6 +18,7 @@ + @@ -119,7 +120,7 @@ - + - @@ -177,7 +177,7 @@ - +