mirror of
https://github.com/Xevion/contest.git
synced 2025-12-12 03:09:38 -06:00
problem 3 finish
This commit is contained in:
57
uil/october-2013/3/java/.idea/workspace.xml
generated
57
uil/october-2013/3/java/.idea/workspace.xml
generated
@@ -2,15 +2,8 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="250f6713-4389-436f-88a0-d6dffc72af7e" name="Default Changelist" comment="">
|
<list default="true" id="250f6713-4389-436f-88a0-d6dffc72af7e" name="Default Changelist" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../../12/bin/CheckerBoard.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/bin/CheckerBoard.class" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../../12/bin/Point.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/bin/Point.class" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../../12/bin/problem12.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/bin/problem12.class" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../../12/src/problem12.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/src/problem12.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/input.dat" beforeDir="false" afterPath="$PROJECT_DIR$/input.dat" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/input.dat" beforeDir="false" afterPath="$PROJECT_DIR$/input.dat" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/problem3.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/problem3.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/problem3.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/problem3.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/../../9/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../9/.idea/workspace.xml" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<ignored path="$PROJECT_DIR$/out/" />
|
<ignored path="$PROJECT_DIR$/out/" />
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
@@ -57,26 +50,26 @@
|
|||||||
</usages-collector>
|
</usages-collector>
|
||||||
<usages-collector id="statistics.file.extensions.edit">
|
<usages-collector id="statistics.file.extensions.edit">
|
||||||
<counts>
|
<counts>
|
||||||
<entry key="dat" value="23" />
|
<entry key="dat" value="105" />
|
||||||
<entry key="java" value="2538" />
|
<entry key="java" value="5234" />
|
||||||
</counts>
|
</counts>
|
||||||
</usages-collector>
|
</usages-collector>
|
||||||
<usages-collector id="statistics.file.types.edit">
|
<usages-collector id="statistics.file.types.edit">
|
||||||
<counts>
|
<counts>
|
||||||
<entry key="JAVA" value="2538" />
|
<entry key="JAVA" value="5234" />
|
||||||
<entry key="PLAIN_TEXT" value="23" />
|
<entry key="PLAIN_TEXT" value="105" />
|
||||||
</counts>
|
</counts>
|
||||||
</usages-collector>
|
</usages-collector>
|
||||||
<usages-collector id="statistics.file.extensions.open">
|
<usages-collector id="statistics.file.extensions.open">
|
||||||
<counts>
|
<counts>
|
||||||
<entry key="dat" value="7" />
|
<entry key="dat" value="8" />
|
||||||
<entry key="java" value="2" />
|
<entry key="java" value="2" />
|
||||||
</counts>
|
</counts>
|
||||||
</usages-collector>
|
</usages-collector>
|
||||||
<usages-collector id="statistics.file.types.open">
|
<usages-collector id="statistics.file.types.open">
|
||||||
<counts>
|
<counts>
|
||||||
<entry key="JAVA" value="2" />
|
<entry key="JAVA" value="2" />
|
||||||
<entry key="PLAIN_TEXT" value="7" />
|
<entry key="PLAIN_TEXT" value="8" />
|
||||||
</counts>
|
</counts>
|
||||||
</usages-collector>
|
</usages-collector>
|
||||||
</session>
|
</session>
|
||||||
@@ -86,12 +79,16 @@
|
|||||||
<file pinned="false" current-in-tab="true">
|
<file pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/src/problem3.java">
|
<entry file="file://$PROJECT_DIR$/src/problem3.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="216">
|
<state relative-caret-position="289">
|
||||||
<caret line="68" column="32" selection-start-line="68" selection-start-column="32" selection-end-line="68" selection-end-column="32" />
|
<caret line="88" column="21" lean-forward="true" selection-start-line="88" selection-start-column="21" selection-end-line="88" selection-end-column="21" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
|
<element signature="e#242#243#0" expanded="true" />
|
||||||
|
<element signature="e#261#262#0" expanded="true" />
|
||||||
<element signature="e#456#457#0" expanded="true" />
|
<element signature="e#456#457#0" expanded="true" />
|
||||||
<element signature="e#517#518#0" expanded="true" />
|
<element signature="e#517#518#0" expanded="true" />
|
||||||
|
<element signature="e#597#598#0" expanded="true" />
|
||||||
|
<element signature="e#658#659#0" expanded="true" />
|
||||||
<element signature="e#641#648#0" expanded="true" />
|
<element signature="e#641#648#0" expanded="true" />
|
||||||
<element signature="e#692#699#0" expanded="true" />
|
<element signature="e#692#699#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
@@ -111,6 +108,9 @@
|
|||||||
<component name="FindInProjectRecents">
|
<component name="FindInProjectRecents">
|
||||||
<findStrings>
|
<findStrings>
|
||||||
<find>out.println</find>
|
<find>out.println</find>
|
||||||
|
<find>out.prin</find>
|
||||||
|
<find>listContains</find>
|
||||||
|
<find>listContai</find>
|
||||||
</findStrings>
|
</findStrings>
|
||||||
</component>
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
@@ -128,8 +128,8 @@
|
|||||||
<component name="IdeDocumentHistory">
|
<component name="IdeDocumentHistory">
|
||||||
<option name="CHANGED_PATHS">
|
<option name="CHANGED_PATHS">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/input.dat" />
|
|
||||||
<option value="$PROJECT_DIR$/src/problem3.java" />
|
<option value="$PROJECT_DIR$/src/problem3.java" />
|
||||||
|
<option value="$PROJECT_DIR$/input.dat" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
@@ -161,7 +161,7 @@
|
|||||||
</panes>
|
</panes>
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568902382723" />
|
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568926039217" />
|
||||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
||||||
</component>
|
</component>
|
||||||
@@ -204,6 +204,15 @@
|
|||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="TodoView">
|
||||||
|
<todo-panel id="selected-file">
|
||||||
|
<is-autoscroll-to-source value="true" />
|
||||||
|
</todo-panel>
|
||||||
|
<todo-panel id="all">
|
||||||
|
<are-packages-shown value="true" />
|
||||||
|
<is-autoscroll-to-source value="true" />
|
||||||
|
</todo-panel>
|
||||||
|
</component>
|
||||||
<component name="ToolWindowManager">
|
<component name="ToolWindowManager">
|
||||||
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
|
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
|
||||||
<editor active="true" />
|
<editor active="true" />
|
||||||
@@ -218,12 +227,12 @@
|
|||||||
<window_info anchor="bottom" id="Messages" weight="0.32939914" />
|
<window_info anchor="bottom" id="Messages" weight="0.32939914" />
|
||||||
<window_info anchor="bottom" id="Message" order="0" />
|
<window_info anchor="bottom" id="Message" order="0" />
|
||||||
<window_info anchor="bottom" id="Find" order="1" />
|
<window_info anchor="bottom" id="Find" order="1" />
|
||||||
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.35193133" />
|
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.29077253" />
|
||||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.39914164" />
|
<window_info anchor="bottom" id="Debug" order="3" weight="0.39914164" />
|
||||||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||||
<window_info anchor="bottom" id="TODO" order="6" />
|
<window_info anchor="bottom" id="TODO" order="6" weight="0.32939914" />
|
||||||
<window_info anchor="bottom" id="Terminal" order="7" />
|
<window_info anchor="bottom" id="Terminal" order="7" weight="0.32939914" />
|
||||||
<window_info anchor="bottom" id="Event Log" order="8" side_tool="true" />
|
<window_info anchor="bottom" id="Event Log" order="8" side_tool="true" />
|
||||||
<window_info anchor="bottom" id="Version Control" order="9" show_stripe_button="false" />
|
<window_info anchor="bottom" id="Version Control" order="9" show_stripe_button="false" />
|
||||||
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
|
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
|
||||||
@@ -267,12 +276,16 @@
|
|||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/src/problem3.java">
|
<entry file="file://$PROJECT_DIR$/src/problem3.java">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="216">
|
<state relative-caret-position="289">
|
||||||
<caret line="68" column="32" selection-start-line="68" selection-start-column="32" selection-end-line="68" selection-end-column="32" />
|
<caret line="88" column="21" lean-forward="true" selection-start-line="88" selection-start-column="21" selection-end-line="88" selection-end-column="21" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="imports" expanded="true" />
|
<element signature="imports" expanded="true" />
|
||||||
|
<element signature="e#242#243#0" expanded="true" />
|
||||||
|
<element signature="e#261#262#0" expanded="true" />
|
||||||
<element signature="e#456#457#0" expanded="true" />
|
<element signature="e#456#457#0" expanded="true" />
|
||||||
<element signature="e#517#518#0" expanded="true" />
|
<element signature="e#517#518#0" expanded="true" />
|
||||||
|
<element signature="e#597#598#0" expanded="true" />
|
||||||
|
<element signature="e#658#659#0" expanded="true" />
|
||||||
<element signature="e#641#648#0" expanded="true" />
|
<element signature="e#641#648#0" expanded="true" />
|
||||||
<element signature="e#692#699#0" expanded="true" />
|
<element signature="e#692#699#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
F
|
F
|
||||||
F |
|
F |
|
||||||
4
|
4
|
||||||
UUUUULL
|
UOOOULOOLUOORD
|
||||||
UULULUL
|
UULULULUL
|
||||||
UUUUUURUULL
|
UOOOUORUOLOOOODOLDR
|
||||||
DRDRDD
|
ODDRDDROD
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,34 +1,55 @@
|
|||||||
import static java.lang.System.*;
|
import static java.lang.System.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Set;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
|
// Point representing and (X, Y) coordinate
|
||||||
class Point {
|
class Point {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
Point(int x, int y) {
|
Point(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
void merge(Point other) {
|
|
||||||
this.x += other.x;
|
// Returns a point which is the translated end-point based on the other point (offset).
|
||||||
this.y += other.y;
|
Point merge(Point other) {
|
||||||
|
return new Point(this.x + other.x, this.y + other.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("Point(%d, %d)", this.x, this.y);
|
return String.format("Point(%d, %d)", this.x, this.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equals(Point other) {
|
||||||
|
return this.x == other.x && this.y == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean collectionContains(Collection<Point> collection, Point point) {
|
||||||
|
for(Point other : collection) {
|
||||||
|
if(point.x == other.x && point.y == other.y) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Class method that searches a List
|
||||||
|
public static int listContains(List<Point> c, Point p) {
|
||||||
|
for(Point o : c) {
|
||||||
|
if(p.x == o.x && p.y == o.y)
|
||||||
|
return c.indexOf(o);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Maze {
|
class Maze {
|
||||||
// Offset Constants
|
// Offset Constants
|
||||||
List<Point> positionOffsets = Arrays.asList(new Point(0, 1), new Point(1, 0), new Point(0, -1), new Point(-1, 0));
|
public List<Point> positionOffsets = Arrays.asList(new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1));
|
||||||
List<String> nameOffsets = Arrays.asList("U R D L".split(" "));
|
private List<String> nameOffsets = Arrays.asList("D R U L".split(" "));
|
||||||
// Maze Data
|
// Maze Data
|
||||||
private List<Point> snake = new ArrayList<Point>();;
|
List<Point> snake = new ArrayList<Point>();;
|
||||||
private List<Point> pellets = new ArrayList<Point>();
|
private List<Point> pellets = new ArrayList<Point>();
|
||||||
private char[][] rawMatrix;
|
private char[][] rawMatrix;
|
||||||
|
|
||||||
@@ -38,14 +59,18 @@ class Maze {
|
|||||||
for(int x = 0; x < 15; x++) {
|
for(int x = 0; x < 15; x++) {
|
||||||
for(int y = 0; y < 15; y++) {
|
for(int y = 0; y < 15; y++) {
|
||||||
switch(rawMatrix[x][y]) {
|
switch(rawMatrix[x][y]) {
|
||||||
|
// Empty Space
|
||||||
case ' ':
|
case ' ':
|
||||||
break;
|
break;
|
||||||
|
// Point Found
|
||||||
case 'X':
|
case 'X':
|
||||||
this.snake.add(new Point(x, y));
|
this.snake.add(new Point(x, y));
|
||||||
break;
|
break;
|
||||||
|
// Pellet Found
|
||||||
case 'F':
|
case 'F':
|
||||||
this.pellets.add(new Point(x, y));
|
this.pellets.add(new Point(x, y));
|
||||||
break;
|
break;
|
||||||
|
// Should not be found based on input data. Something has gone wrong/input data is invalid.
|
||||||
default:
|
default:
|
||||||
out.println("Possibly faulty Maze Input with item \"" + rawMatrix[x][y] + "\" found.");
|
out.println("Possibly faulty Maze Input with item \"" + rawMatrix[x][y] + "\" found.");
|
||||||
break;
|
break;
|
||||||
@@ -56,27 +81,33 @@ class Maze {
|
|||||||
|
|
||||||
// Simulate the snake game using instructions
|
// Simulate the snake game using instructions
|
||||||
String simulate(String input) {
|
String simulate(String input) {
|
||||||
char curDirection = 'R';
|
String curDirection = "R";
|
||||||
int score = 0;
|
int score = 0;
|
||||||
for(int i = 0; i < input.length(); i++) {
|
for(int i = 0; i < input.length(); i++) {
|
||||||
// Calculate the offset based on the current instruction
|
// Calculate the offset based on the current instruction
|
||||||
Point offset;
|
Point offset;
|
||||||
char curOffset = input.charAt(i);
|
String curOffset = input.substring(i, i + 1);
|
||||||
if(curOffset == 'O')
|
if(!curDirection.equals(curOffset) && !curOffset.equals("O"))
|
||||||
|
curDirection = curOffset;
|
||||||
|
if(curOffset.equals("O"))
|
||||||
offset = positionOffsets.get(nameOffsets.indexOf(curDirection));
|
offset = positionOffsets.get(nameOffsets.indexOf(curDirection));
|
||||||
else
|
else
|
||||||
offset = positionOffsets.get(nameOffsets.indexOf(input.substring(i, i+1)));
|
offset = positionOffsets.get(nameOffsets.indexOf(curOffset));
|
||||||
out.println(offset);
|
|
||||||
// Calculate the new point, ensure it's real
|
// Calculate the new point, ensure it's real
|
||||||
Point newPoint = snake.get(snake.size() - 1);
|
Point newPoint = snake.get(snake.size() - 1);
|
||||||
newPoint.merge(offset);
|
newPoint = newPoint.merge(offset);
|
||||||
|
// New Point was out of bounds, cannot continue
|
||||||
if(!this.inBounds(newPoint))
|
if(!this.inBounds(newPoint))
|
||||||
return "GAME OVER @ " + newPoint;
|
return "GAME OVER";
|
||||||
// Add new point, discard end of snake to simulate it's movement
|
// Add new point, discard end of snake to simulate it's movement
|
||||||
snake.add(newPoint);
|
|
||||||
snake.remove(0);
|
snake.remove(0);
|
||||||
// Check if we're at a pellet
|
snake.add(newPoint);
|
||||||
score += pellets.contains(newPoint) ? 1 : 0;
|
// Check if we're at a pellet, add score.
|
||||||
|
int pelletIndex = Point.listContains(pellets, newPoint);
|
||||||
|
if(pelletIndex != -1) {
|
||||||
|
score += 1;
|
||||||
|
this.pellets.remove(pelletIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Integer.toString(score);
|
return Integer.toString(score);
|
||||||
}
|
}
|
||||||
@@ -91,7 +122,9 @@ class Maze {
|
|||||||
for(int x = 0; x < 15; x++) {
|
for(int x = 0; x < 15; x++) {
|
||||||
String[] temp = new String[15];
|
String[] temp = new String[15];
|
||||||
for(int y = 0; y < 15; y++) {
|
for(int y = 0; y < 15; y++) {
|
||||||
temp[y] = Character.toString(rawMatrix[x][y]);
|
Point point = new Point(x, y);
|
||||||
|
// Priority: Empty Space < Pellet < Snake
|
||||||
|
temp[y] = Point.collectionContains(this.snake, point) ? "X" : (Point.collectionContains(this.pellets, point) ? "F" : " ");
|
||||||
}
|
}
|
||||||
lines[x] = String.join(" - ", temp);
|
lines[x] = String.join(" - ", temp);
|
||||||
}
|
}
|
||||||
@@ -113,7 +146,6 @@ public class problem3 {
|
|||||||
rawMatrix[x][y] = line.charAt(y);
|
rawMatrix[x][y] = line.charAt(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Maze originalMaze = new Maze(rawMatrix);
|
|
||||||
|
|
||||||
// Read each of the inputs
|
// Read each of the inputs
|
||||||
int lines = Integer.parseInt(read.nextLine());
|
int lines = Integer.parseInt(read.nextLine());
|
||||||
@@ -123,10 +155,10 @@ public class problem3 {
|
|||||||
|
|
||||||
// Simulate inputs
|
// Simulate inputs
|
||||||
for(String input : inputs) {
|
for(String input : inputs) {
|
||||||
Maze temp = originalMaze;
|
Maze maze = new Maze(rawMatrix);
|
||||||
out.println(temp.simulate(input));
|
String pellets = maze.simulate(input);
|
||||||
out.println(temp);
|
// Uncomment to display the final position of the maze
|
||||||
|
// out.println(maze);
|
||||||
|
out.println(pellets); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user