fixed snake pathfinding

This commit is contained in:
Xevion
2019-09-16 00:06:59 -05:00
parent 78b904bcf2
commit 493352a14f
6 changed files with 95 additions and 30 deletions

View File

@@ -445,4 +445,6 @@ This is a rather long problem, so let's split it up into parts.
Class X is a implementation of the Comparable Interface, and is essentially a method for comparing Strings when sorted. Focus on the `compareTo` method.
The `compareTo` method is how comparables "compare", and it returns a integer value to representation how it should be placed in the array. The array is sorted in descending order when `Collections.sort` is called on it.
The `compareTo` method is how comparables "compare", and it returns a integer value to representation how it should be placed in the array. The array is sorted in descending order when `Collections.sort` is called on it.
The integer it returns is calculated based on the length first: if the two Strings have the same length, it returns the result of the two strings `compareTo` method, but if they're not the same length, it returns the difference in length of the two Strings.

View File

@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="5ee3d13c-335f-4b45-baa5-1d7b6e58ccd6" name="Default Changelist" comment="" />
<list default="true" id="5ee3d13c-335f-4b45-baa5-1d7b6e58ccd6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/question26.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/question26.java" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@@ -40,16 +43,35 @@
</counts>
</usages-collector>
</session>
<session id="-2041611852">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.open.time.0" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="java" value="461" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="JAVA" value="461" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/question26.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="15" column="30" selection-start-line="15" selection-start-column="30" selection-end-line="15" selection-end-column="30" />
<state relative-caret-position="533">
<caret line="42" column="62" selection-start-line="42" selection-start-column="62" selection-end-line="42" selection-end-column="62" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#435#436#0" expanded="true" />
<element signature="e#466#467#0" expanded="true" />
</folding>
</state>
@@ -65,6 +87,9 @@
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." />
</component>
<component name="GradleLocalSettings">
<option name="projectSyncType">
<map>
@@ -87,6 +112,9 @@
<option name="width" value="1440" />
<option name="height" value="788" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
@@ -108,7 +136,7 @@
</panes>
</component>
<component name="PropertiesComponent">
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568588789665" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568600612753" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="RunDashboard">
@@ -152,8 +180,9 @@
</component>
<component name="ToolWindowManager">
<frame x="1912" y="-8" width="1936" height="1066" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18603411" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.1881663" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
@@ -162,7 +191,7 @@
<window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.2306867" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.2306867" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@@ -170,7 +199,7 @@
<window_info anchor="bottom" id="Terminal" order="7" />
<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="Messages" order="10" />
<window_info anchor="bottom" id="Messages" order="10" weight="0.32939914" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -187,10 +216,11 @@
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/question26.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="15" column="30" selection-start-line="15" selection-start-column="30" selection-end-line="15" selection-end-column="30" />
<state relative-caret-position="533">
<caret line="42" column="62" selection-start-line="42" selection-start-column="62" selection-end-line="42" selection-end-column="62" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#435#436#0" expanded="true" />
<element signature="e#466#467#0" expanded="true" />
</folding>
</state>

View File

@@ -1,5 +1,6 @@
import static java.lang.System.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -16,6 +17,20 @@ class X implements Comparable<X> {
public String toString() {
return this.str;
}
public int[] getValues() {
int[] values = new int[this.str.length()];
for(int i = 0; i < this.str.length(); i++) {
values[i] = (int) this.str.charAt(i);
}
return values;
}
public int getSum() {
int sum = 0;
for(int val : this.getValues()) {
sum += val;
}
return sum;
}
}
class question26 {
@@ -26,5 +41,6 @@ class question26 {
w.add(new X(sub));
Collections.sort(w);
out.println(w);
out.println(Arrays.toString(new X("Hello").getValues()));
}
}