mirror of
https://github.com/Xevion/contest.git
synced 2025-12-17 22:11:28 -06:00
rename folders
This commit is contained in:
205
uil/october-2013/3/input-generator/main.py
Normal file
205
uil/october-2013/3/input-generator/main.py
Normal file
@@ -0,0 +1,205 @@
|
||||
import math, time, random
|
||||
|
||||
class Node(object):
|
||||
def __init__(self, parent=None, position=None):
|
||||
self.parent, self.position = parent, position
|
||||
|
||||
self.g, self.h, self.f = 0, 0, 0
|
||||
|
||||
def __eq__(self, other):
|
||||
assert type(other) == Node, "Can only compare equality against other Node objects"
|
||||
return self.position == other.position
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Node ({self.position[0]}, {self.position[1]})>'
|
||||
|
||||
# Generate a grid and return it to the user
|
||||
class SnakeGrid(object):
|
||||
def __init__(self, x, y, length=3):
|
||||
self.x, self.y, self.length, self.sleepTime = x, y, length, 0.0
|
||||
self.offsets = [[0, 1], [1, 0], [-1, 0], [0, -1]]
|
||||
self.generate()
|
||||
|
||||
def sleep(self, seconds):
|
||||
self.sleepTime += (seconds, time.sleep(seconds))[0]
|
||||
|
||||
def generate(self):
|
||||
assert self.x > 2 + self.length and self.y > 3, "Dimensions must be able to at least fit the snake"
|
||||
|
||||
# Grid is a matrix of single space strings
|
||||
self.matrix = [[' ' for xx in range(self.x + 1)] for yy in range(self.y + 1)]
|
||||
|
||||
# Choose a initial position
|
||||
self.positions = [self.getPos(-1, -1)]
|
||||
self.mark(self.positions[0])
|
||||
curlength = self.length - 1
|
||||
|
||||
# Start drawing up the snake
|
||||
while curlength > 0:
|
||||
left, right = [self.positions[0][0], self.positions[0][1] - 1], [self.positions[-1][0], self.positions[-1][1] + 1]
|
||||
canLeft, canRight = self.available(left), self.available(right)
|
||||
curlength -= 1
|
||||
|
||||
# If both options are available, just choose one and act like the other is unavailable
|
||||
if canLeft and canRight:
|
||||
if random.choice([True, False]): canLeft = False
|
||||
else: canRight = False
|
||||
|
||||
if canLeft != canRight:
|
||||
if canLeft:
|
||||
self.mark(left)
|
||||
self.positions.insert(0, left)
|
||||
if canRight:
|
||||
self.mark(right)
|
||||
self.positions.append(right)
|
||||
elif not (canLeft or canRight):
|
||||
print(positions, left, right)
|
||||
print("Could not resolve any position to use...?")
|
||||
|
||||
# Populate with 3-7 pellets
|
||||
for _ in range(random.randint(2, 5)):
|
||||
while True:
|
||||
pos = self.getPos()
|
||||
if self.available(pos):
|
||||
self.mark(pos, 'F')
|
||||
break
|
||||
|
||||
# Pythagorean distance calculation
|
||||
def distance(self, pos1, pos2):
|
||||
return math.sqrt(((pos1[0] - pos2[0]) ** 2) + ((pos1[1] - pos2[1]) ** 2))
|
||||
|
||||
# Returns all positions with the specified character (by default, 'F', for pellets)
|
||||
def pellets(self, char='F'):
|
||||
pelletss = []
|
||||
for yy in range(self.y):
|
||||
for xx in range(self.x):
|
||||
if self.available([xx, yy], look=char):
|
||||
pelletss.append([xx, yy])
|
||||
return pelletss
|
||||
|
||||
# Returns the best pellet to path to based on distance and a specified blacklist of positions
|
||||
def bestPellet(self, curpos, blacklist=[]):
|
||||
potential = self.pellets()
|
||||
if blacklist:
|
||||
potential = list(filter(lambda item : item not in blacklist, potential))
|
||||
# Returns None if no potential pellets are in due to blacklist
|
||||
if not potential:
|
||||
return None
|
||||
return min(potential, key=lambda pos : self.distance(curpos, pos))
|
||||
|
||||
# Quick code for calcul
|
||||
def merge(self, pos1, pos2):
|
||||
return [pos1[0] + pos2[0], pos1[1] + pos2[1]]
|
||||
|
||||
# Generater a solution for the maz
|
||||
def solution(self, length=20):
|
||||
def build_path(current_node):
|
||||
path = []
|
||||
current = current_node
|
||||
while current is not None:
|
||||
path.append(current.position)
|
||||
current = current.parent
|
||||
return str(path[::-1])
|
||||
|
||||
# Pathfinding initial constants
|
||||
start_node = Node(None, self.positions[-1])
|
||||
end_node = Node(None, self.bestPellet(start_node.position))
|
||||
open_list, closed_list = [start_node], []
|
||||
finished_end_nodes = []
|
||||
pathdist = 0
|
||||
output = ""
|
||||
|
||||
while len(open_list) > 0:
|
||||
self.sleep(0.125)
|
||||
pathdist += 1
|
||||
# Choose the best node to work on
|
||||
current_index, current_node = min(enumerate(open_list), key=lambda item : item[1].f)
|
||||
open_list.pop(current_index)
|
||||
closed_list.append(current_node)
|
||||
|
||||
|
||||
# Check if we've hit the maximum distance
|
||||
if pathdist >= length:
|
||||
return build_path(current_node)
|
||||
|
||||
# If we've hit the "end node", but still distance to travel, setup a new one
|
||||
if current_node == end_node:
|
||||
finished_end_nodes.append(end_node)
|
||||
end_node = self.bestPellet(blacklist=finished_end_nodes)
|
||||
# if we've acquired all pellets by chance
|
||||
if end_node is None:
|
||||
return build_path(current_node)
|
||||
|
||||
# Basically iterates upon all positions next to the current node dependent on the cardinal directions
|
||||
for offset in self.offsets:
|
||||
child = self.merge(current_node.position, offset)
|
||||
# Ensure in bounds
|
||||
if self.inBounds(child):
|
||||
child = Node(parent=current_node, position=child)
|
||||
|
||||
# Ensure not already a closed position
|
||||
if not child in closed_list:
|
||||
child.g = current_node.g + 1
|
||||
child.h = self.distance(child.position, end_node.position)
|
||||
child.f = child.g + child.h
|
||||
|
||||
# Ensure that child node is
|
||||
for open_node in open_list:
|
||||
if child == open_node:
|
||||
if child.g > open_node.g:
|
||||
continue
|
||||
|
||||
open_list.append(child)
|
||||
|
||||
return output
|
||||
|
||||
# Quick method for getting a position with the offsets provided
|
||||
def getPos(self, xoffset=0, yoffset=0):
|
||||
return [random.randint(1, self.x + xoffset), random.randint(1, self.y + yoffset)]
|
||||
|
||||
# Quick method for marking a postiion
|
||||
def mark(self, pos, marker='X'):
|
||||
self.matrix[pos[0]][pos[1]] = marker
|
||||
|
||||
# Mechansim for determining whether a position is in the boundaries of the matrix
|
||||
def inBounds(self, pos):
|
||||
return all([pos[0] >= 0, pos[1] >= 0, pos[1] < self.y, pos[0] < self.x])
|
||||
|
||||
# Determine whether a position is available for use
|
||||
def available(self, pos, look=' '):
|
||||
return (self.matrix[pos[0]][pos[1]] == look) if self.inBounds(pos) else False
|
||||
|
||||
def __repr__(self):
|
||||
return '\n'.join(' - '.join(_) for _ in self.matrix)
|
||||
|
||||
# Driver Code
|
||||
if __name__ == "__main__":
|
||||
# User Adjustable Constants
|
||||
timing = 0.050
|
||||
iterations = 1
|
||||
size = (15, 15)
|
||||
|
||||
# Build Constants
|
||||
roundTime = lambda seconds : str(round((seconds) * 1000, 2)) + 'ms'
|
||||
centerSize = (2 + len(str(iterations)))
|
||||
dividerTotal = (4 * size[0]) - centerSize
|
||||
dividerCustom = ('-' * (dividerTotal // 2)) + ' {} ' + ('-' * (dividerTotal // 2))
|
||||
dividerTotal = '-' * (dividerTotal + 4)
|
||||
t1 = time.time()
|
||||
|
||||
# Build and prints matrixes
|
||||
for x in range(iterations):
|
||||
snakegrid = SnakeGrid(size[0], size[1], 3)
|
||||
print(dividerCustom.format(str(x+1).zfill(len(str(iterations)))))
|
||||
print(snakegrid)
|
||||
print(dividerTotal)
|
||||
print(snakegrid.solution())
|
||||
time.sleep(timing)
|
||||
print(dividerTotal)
|
||||
|
||||
# Finish and print timing statistics
|
||||
t2 = time.time()
|
||||
print(f'Processing Time : {roundTime(t2 - t1 - (timing * iterations) - snakegrid.sleepTime)}')
|
||||
print(f'Artificial Time : {roundTime((timing * iterations) + snakegrid.sleepTime)}')
|
||||
print(f'Total Time : {roundTime(t2 - t1)}')
|
||||
print(dividerTotal)
|
||||
6
uil/october-2013/3/java/.idea/misc.xml
generated
Normal file
6
uil/october-2013/3/java/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
uil/october-2013/3/java/.idea/modules.xml
generated
Normal file
8
uil/october-2013/3/java/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/3.iml" filepath="$PROJECT_DIR$/3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
198
uil/october-2013/3/java/.idea/workspace.xml
generated
Normal file
198
uil/october-2013/3/java/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,198 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="250f6713-4389-436f-88a0-d6dffc72af7e" name="Default Changelist" comment="" />
|
||||
<ignored path="$PROJECT_DIR$/out/" />
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FUSProjectUsageTrigger">
|
||||
<session id="-261025025">
|
||||
<usages-collector id="statistics.lifecycle.project">
|
||||
<counts>
|
||||
<entry key="project.open.time.2" value="1" />
|
||||
<entry key="project.opened" value="1" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.open">
|
||||
<counts>
|
||||
<entry key="java" value="1" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.open">
|
||||
<counts>
|
||||
<entry key="JAVA" value="1" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.edit">
|
||||
<counts>
|
||||
<entry key="java" value="44" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.edit">
|
||||
<counts>
|
||||
<entry key="JAVA" value="44" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
</session>
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf>
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/problem3.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="187">
|
||||
<caret line="11" column="15" selection-start-line="11" selection-start-column="15" selection-end-line="11" selection-end-column="15" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="GradleLocalSettings">
|
||||
<option name="projectSyncType">
|
||||
<map>
|
||||
<entry key="A:/Programming/Modding/Minecraft/EnderStorage" value="PREVIEW" />
|
||||
<entry key="A:/Programming/Modding/Minecraft/Fabric/fabric-example-mod" value="PREVIEW" />
|
||||
<entry key="A:/Programming/Modding/Minecraft/HelloWorldMod" value="PREVIEW" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/src/problem3.java" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds" extendedState="6">
|
||||
<option name="x" value="351" />
|
||||
<option name="y" value="-16" />
|
||||
<option name="width" value="974" />
|
||||
<option name="height" value="1057" />
|
||||
</component>
|
||||
<component name="ProjectView">
|
||||
<navigator proportions="" version="1">
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="Scope" />
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="3" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="3" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568536537998" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
<RuleState>
|
||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
<RuleState>
|
||||
<option name="name" value="StatusDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="250f6713-4389-436f-88a0-d6dffc72af7e" name="Default Changelist" comment="" />
|
||||
<created>1568523737759</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1568523737759</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Image Layers" />
|
||||
<window_info id="Designer" />
|
||||
<window_info id="UI Designer" />
|
||||
<window_info id="Capture Tool" />
|
||||
<window_info id="Favorites" side_tool="true" />
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Terminal" />
|
||||
<window_info anchor="bottom" id="Event Log" 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" />
|
||||
<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" />
|
||||
<window_info anchor="bottom" id="TODO" order="6" />
|
||||
<window_info anchor="right" id="Palette" />
|
||||
<window_info anchor="right" id="Theme Preview" />
|
||||
<window_info anchor="right" id="Capture Analysis" />
|
||||
<window_info anchor="right" id="Palette	" />
|
||||
<window_info anchor="right" id="Maven Projects" />
|
||||
<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" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="VcsContentAnnotationSettings">
|
||||
<option name="myLimit" value="2678400000" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/src/problem3.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="187">
|
||||
<caret line="11" column="15" selection-start-line="11" selection-start-column="15" selection-end-line="11" selection-end-column="15" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ProjectJDKs.UI">
|
||||
<settings>
|
||||
<last-edited>11</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
||||
11
uil/october-2013/3/java/3.iml
Normal file
11
uil/october-2013/3/java/3.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
19
uil/october-2013/3/java/src/problem3.java
Normal file
19
uil/october-2013/3/java/src/problem3.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import static java.lang.System.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class problem3 {
|
||||
public static void main(String[] args ) throws FileNotFoundException {
|
||||
// Constants
|
||||
File input = new File("input1.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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user