mirror of
https://github.com/Xevion/contest.git
synced 2025-12-09 20:06:44 -06:00
UIL move
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import os, sys
|
||||
|
||||
mappings = {
|
||||
'@' : ['at'],
|
||||
'&' : ['and'],
|
||||
'1' : ['one', 'won'],
|
||||
'2' : ['to', 'too', 'two'],
|
||||
'4' : ['for', 'four'],
|
||||
'b' : ['bea', 'be', 'bee'],
|
||||
'c' : ['sea', 'see'],
|
||||
'i' : ['eye'],
|
||||
'o' : ['oh', 'owe'],
|
||||
'r' : ['are'],
|
||||
'u' : ['you'],
|
||||
'y' : ['why']
|
||||
}
|
||||
|
||||
# gets the largest and smallest possible subs
|
||||
minSub = min([min(list(map(len, vals))) for vals in mappings.values()])
|
||||
maxSub = max([max(list(map(len, vals))) for vals in mappings.values()])
|
||||
|
||||
# Gets the token ('are' -> 'r') for a sub, case sensitive
|
||||
def getToken(sub):
|
||||
for key in mappings.keys():
|
||||
if sub in mappings[key]:
|
||||
return key
|
||||
|
||||
def processWord(word):
|
||||
processed = [False] * len(word)
|
||||
# For every character in the word
|
||||
index = 0
|
||||
while index < len(word):
|
||||
possible = []
|
||||
for length in range(minSub, maxSub + 1):
|
||||
if index + length > len(word):
|
||||
continue
|
||||
sub = word[index:index + length]
|
||||
token = getToken(sub.lower())
|
||||
if token:
|
||||
# Sometimes mulitple tokens can appear for the same one, we just select the one that is longest
|
||||
possible.append((token, len(sub), sub))
|
||||
# A token replacement has been found at this index
|
||||
if possible:
|
||||
# Find the best one, based on the sub
|
||||
select = max(possible, key=lambda item : item[1])
|
||||
# print(index, select, word[index:index + select[1]])
|
||||
word = word[:index] + (select[0].title() if select[2].istitle() else select[0]) + word[index + select[1]:]
|
||||
# word[index:index + select[1]] = select[0]
|
||||
index += len(select[0])
|
||||
else:
|
||||
index += 1
|
||||
return word
|
||||
|
||||
# Process a single line
|
||||
def processLine(line):
|
||||
return ' '.join([processWord(word) for word in line.split(' ')])
|
||||
|
||||
# Drive Code
|
||||
def main():
|
||||
path = os.path.join(sys.path[0], 'input')
|
||||
data = open(path, 'r').read().split('\n')[1:]
|
||||
print('\n'.join(map(processLine, data)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,6 @@
|
||||
5
|
||||
H 2 0:13
|
||||
A 2 0:19
|
||||
H 1 0:52
|
||||
H 1 0:52
|
||||
A 3 1:08
|
||||
@@ -0,0 +1,2 @@
|
||||
1
|
||||
H 1 16:00
|
||||
@@ -1,65 +1,41 @@
|
||||
import os, sys
|
||||
import datetime, re, os, sys
|
||||
|
||||
mappings = {
|
||||
'@' : ['at'],
|
||||
'&' : ['and'],
|
||||
'1' : ['one', 'won'],
|
||||
'2' : ['to', 'too', 'two'],
|
||||
'4' : ['for', 'four'],
|
||||
'b' : ['bea', 'be', 'bee'],
|
||||
'c' : ['sea', 'see'],
|
||||
'i' : ['eye'],
|
||||
'o' : ['oh', 'owe'],
|
||||
'r' : ['are'],
|
||||
'u' : ['you'],
|
||||
'y' : ['why']
|
||||
}
|
||||
pattern = r'([HA]) (\d) (\d+):(\d+)'
|
||||
mmsspattern = '%M:%S'
|
||||
|
||||
# gets the largest and smallest possible subs
|
||||
minSub = min([min(list(map(len, vals))) for vals in mappings.values()])
|
||||
maxSub = max([max(list(map(len, vals))) for vals in mappings.values()])
|
||||
# Process the input for a single niput
|
||||
def process(rawinput):
|
||||
def getBest():
|
||||
return max(score.items(), key=lambda x:x[1])[0]
|
||||
score = {'H' : 0, 'A' : 0}
|
||||
leads = {'H' : 0, 'A' : 0}
|
||||
rawinput = '\n'.join(rawinput.split('\n')[1:])
|
||||
events = re.finditer(pattern, rawinput)
|
||||
curLead = ''
|
||||
lastTime = datetime.datetime(1990, 1, 1, 0, 0, 0)
|
||||
gameEnd = datetime.datetime(1990, 1, 1, 1, 30)
|
||||
for event in events:
|
||||
# Create the formatted timecode, add the score
|
||||
timecode = '{}:{}'.format(event.group(3).zfill(2), event.group(4).zfill(2))
|
||||
curtime = datetime.datetime.strptime(timecode, mmsspattern)
|
||||
score[event.group(1)] += int(event.group(2))
|
||||
# Get the team in the lead and if it's different
|
||||
best = getBest()
|
||||
leads[best] += int((curtime - lastTime).seconds)
|
||||
lastTime = curtime
|
||||
# if gameEnd > lastTime:
|
||||
# leads[best] += (gameEnd - lastTime).seconds
|
||||
return '{} {} {}'.format(getBest(), leads['H'], leads['A'])
|
||||
|
||||
# Gets the token ('are' -> 'r') for a sub, case sensitive
|
||||
def getToken(sub):
|
||||
for key in mappings.keys():
|
||||
if sub in mappings[key]:
|
||||
return key
|
||||
|
||||
def processWord(word):
|
||||
processed = [False] * len(word)
|
||||
# For every character in the word
|
||||
index = 0
|
||||
while index < len(word):
|
||||
possible = []
|
||||
for length in range(minSub, maxSub + 1):
|
||||
if index + length > len(word):
|
||||
continue
|
||||
sub = word[index:index + length]
|
||||
token = getToken(sub.lower())
|
||||
if token:
|
||||
# Sometimes mulitple tokens can appear for the same one, we just select the one that is longest
|
||||
possible.append((token, len(sub), sub))
|
||||
# A token replacement has been found at this index
|
||||
if possible:
|
||||
# Find the best one, based on the sub
|
||||
select = max(possible, key=lambda item : item[1])
|
||||
# print(index, select, word[index:index + select[1]])
|
||||
word = word[:index] + (select[0].title() if select[2].istitle() else select[0]) + word[index + select[1]:]
|
||||
# word[index:index + select[1]] = select[0]
|
||||
index += len(select[0])
|
||||
else:
|
||||
index += 1
|
||||
return word
|
||||
|
||||
# Process a single line
|
||||
def processLine(line):
|
||||
return ' '.join([processWord(word) for word in line.split(' ')])
|
||||
|
||||
# Drive Code
|
||||
# Driver code
|
||||
def main():
|
||||
path = os.path.join(sys.path[0], 'input')
|
||||
data = open(path, 'r').read().split('\n')[1:]
|
||||
print('\n'.join(map(processLine, data)))
|
||||
# Read inputs
|
||||
inputs = [os.path.join(sys.path[0], 'inputs', x) for x in
|
||||
os.listdir(os.path.join(sys.path[0], 'inputs'))]
|
||||
inputs = [open(path).read() for path in inputs]
|
||||
for rawinput in inputs:
|
||||
print(process(rawinput))
|
||||
print('-'*19)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -4,25 +4,41 @@ def process(item):
|
||||
# Constants and initial values
|
||||
stocks, (n, m) = item[1], item[0]
|
||||
peaks, valleys = [], []
|
||||
possiblePeaks, possibleValleys = range(n, len(stocks) - n), range(m, len(stocks) - m)
|
||||
# Check all possible peaks
|
||||
for index in possiblePeaks:
|
||||
isPeak = True
|
||||
for index in range(len(stocks)):
|
||||
isPeak, isValley = True, True
|
||||
# Peak Checking
|
||||
for i in range(1, n + 1):
|
||||
if not stocks[index - i] < stocks[index] or not stocks[index] > stocks[index + i]:
|
||||
isPeak = False
|
||||
if isPeak:
|
||||
peaks.append(index)
|
||||
print(peaks)
|
||||
# Check all possible valleys
|
||||
for index in possibleValleys:
|
||||
isValley = True
|
||||
# If we're no the first index
|
||||
if index - i >= 0:
|
||||
# If position behind us is lower
|
||||
if not stocks[index] > stocks[index - i]:
|
||||
isPeak = False
|
||||
break
|
||||
# If we're not the final index
|
||||
if index + i < len(stocks):
|
||||
# and position in front of us is lower
|
||||
if not stocks[index] > stocks[index + i]:
|
||||
isPeak = False
|
||||
break
|
||||
# Valley checking
|
||||
for i in range(1, m + 1):
|
||||
if not stocks[index - i] > stocks[index] or not stocks[index] < stocks[index + i]:
|
||||
isValley = False
|
||||
if isValley:
|
||||
valleys.append(index)
|
||||
print(valleys)
|
||||
# If we're not the first index
|
||||
if index - i >= 0:
|
||||
# if position behind us is higher
|
||||
if not stocks[index] < stocks[index - i]:
|
||||
isValley = False
|
||||
break
|
||||
# If we're not the final index
|
||||
if index + i < len(stocks):
|
||||
# and position in front of us is higher
|
||||
if not stocks[index] < stocks[index + i]:
|
||||
isValley = False
|
||||
break
|
||||
if isPeak: peaks.append(index)
|
||||
if isValley: valleys.append(index)
|
||||
print(f'n{n}, m{m}')
|
||||
print('{0}{1}\n{0}{2}'.format('-> ', peaks, valleys))
|
||||
return len(peaks), len(valleys)
|
||||
|
||||
# Driver code for all inputs in folder
|
||||
|
||||
@@ -8,6 +8,14 @@ Most of these problems seem modestly easy, if I'm being honest.
|
||||
|
||||
## Progress
|
||||
|
||||
#1 : Unsovled
|
||||
#A : **Solved**
|
||||
|
||||
#2 : **Solved**
|
||||
#B : **Solved**
|
||||
|
||||
#C : Unsolved
|
||||
|
||||
#D : **Solved**
|
||||
|
||||
#E : **Solved**
|
||||
|
||||
#F : **Solved**
|
||||
6
uil/October 2013 Set/1/java/.idea/misc.xml
generated
Normal file
6
uil/October 2013 Set/1/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 Set/1/java/.idea/modules.xml
generated
Normal file
8
uil/October 2013 Set/1/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$/1.iml" filepath="$PROJECT_DIR$/1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
311
uil/October 2013 Set/1/java/.idea/workspace.xml
generated
Normal file
311
uil/October 2013 Set/1/java/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,311 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="23ea4cb8-4435-47e1-9ce5-e2565ff7e5f3" 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="132001983">
|
||||
<usages-collector id="statistics.lifecycle.project">
|
||||
<counts>
|
||||
<entry key="project.closed" value="3" />
|
||||
<entry key="project.open.time.0" value="2" />
|
||||
<entry key="project.open.time.2" value="1" />
|
||||
<entry key="project.opened" value="3" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.open">
|
||||
<counts>
|
||||
<entry key="class" value="1" />
|
||||
<entry key="java" value="2" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.open">
|
||||
<counts>
|
||||
<entry key="CLASS" value="1" />
|
||||
<entry key="JAVA" value="2" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.edit">
|
||||
<counts>
|
||||
<entry key="java" value="571" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.edit">
|
||||
<counts>
|
||||
<entry key="JAVA" value="571" />
|
||||
</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/problem1.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="329">
|
||||
<caret line="54" column="26" selection-start-line="54" selection-start-column="26" selection-end-line="54" selection-end-column="26" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</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/problem1.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="PackagesPane" />
|
||||
<pane id="Scope" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="1" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="1" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="1" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="1" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="out" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="1" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="1" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="out" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="production" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="1" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="1" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="out" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="production" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="1" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="1" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="1" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="src" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568523089262" />
|
||||
<property name="project.structure.last.edited" value="Modules" />
|
||||
<property name="project.structure.proportion" value="0.0" />
|
||||
<property name="project.structure.side.proportion" value="0.0" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="F:\Programming\Java\UIL\October 2013 Set\1\src" />
|
||||
</key>
|
||||
</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="RunManager">
|
||||
<configuration name="problem1" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="problem1" />
|
||||
<module name="1" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.problem1" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="23ea4cb8-4435-47e1-9ce5-e2565ff7e5f3" name="Default Changelist" comment="" />
|
||||
<created>1568522090590</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1568522090590</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
|
||||
<layout>
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2553305" />
|
||||
<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" />
|
||||
<window_info id="UI Designer" order="4" />
|
||||
<window_info id="Capture Tool" order="5" />
|
||||
<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.32939914" />
|
||||
<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="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="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" />
|
||||
<window_info anchor="right" id="Palette" order="3" />
|
||||
<window_info anchor="right" id="Capture Analysis" order="4" />
|
||||
<window_info anchor="right" id="Theme Preview" order="5" />
|
||||
<window_info anchor="right" id="Palette	" order="6" />
|
||||
<window_info anchor="right" id="Maven Projects" order="7" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="VcsContentAnnotationSettings">
|
||||
<option name="myLimit" value="2678400000" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/problem1.class" />
|
||||
<entry file="file://$PROJECT_DIR$/src/problem1.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="329">
|
||||
<caret line="54" column="26" selection-start-line="54" selection-start-column="26" selection-end-line="54" selection-end-column="26" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ArtifactsStructureConfigurable.UI">
|
||||
<settings>
|
||||
<artifact-editor />
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<state key="FacetStructureConfigurable.UI">
|
||||
<settings>
|
||||
<last-edited>No facets are configured</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<state key="GlobalLibrariesConfigurable.UI">
|
||||
<settings>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<state key="JdkListConfigurable.UI">
|
||||
<settings>
|
||||
<last-edited>1.8</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<state key="ModuleStructureConfigurable.UI">
|
||||
<settings>
|
||||
<last-edited>1</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
<option value="0.6" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<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>
|
||||
<state key="ProjectLibrariesConfigurable.UI">
|
||||
<settings>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
||||
11
uil/October 2013 Set/1/java/1.iml
Normal file
11
uil/October 2013 Set/1/java/1.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>
|
||||
4
uil/October 2013 Set/1/java/input1.dat
Normal file
4
uil/October 2013 Set/1/java/input1.dat
Normal file
@@ -0,0 +1,4 @@
|
||||
3
|
||||
1 2 3 3
|
||||
10 10 10 10 10 10 10 10 10 10
|
||||
2 3 4 5 5 9 8 7 5 5 3 2 1
|
||||
BIN
uil/October 2013 Set/1/java/out/production/1/problem1.class
Normal file
BIN
uil/October 2013 Set/1/java/out/production/1/problem1.class
Normal file
Binary file not shown.
85
uil/October 2013 Set/1/java/src/problem1.java
Normal file
85
uil/October 2013 Set/1/java/src/problem1.java
Normal file
@@ -0,0 +1,85 @@
|
||||
import static java.lang.System.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class problem1 {
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
// Main Constants
|
||||
File input = new File("input1.dat");
|
||||
Scanner scan = new Scanner(input);
|
||||
List<String> output = new ArrayList<String>();
|
||||
|
||||
// Process the input data
|
||||
int lineCount = scan.nextInt();
|
||||
scan.nextLine();
|
||||
for(int i = 0; i < lineCount; i++) {
|
||||
output.add(process(scan.nextLine()));
|
||||
}
|
||||
|
||||
// Print out the array of processed inputs
|
||||
output.add(0, "mean median mode");
|
||||
for(String line : output) {
|
||||
out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
static String process(String input) {
|
||||
// Sub-constants
|
||||
Scanner read = new Scanner(input);
|
||||
int sum = 0;
|
||||
Map<Integer, Integer> mode = new HashMap<Integer, Integer>();
|
||||
List<Integer> median = new ArrayList<Integer>();
|
||||
|
||||
// Read each number in the file in sequence
|
||||
while(read.hasNextInt()) {
|
||||
int newread = read.nextInt();
|
||||
sum += newread;
|
||||
// Add key to dictionary and list
|
||||
median.add(newread);
|
||||
if(mode.containsKey(newread))
|
||||
mode.put(newread, mode.get(newread) + 1);
|
||||
else
|
||||
mode.put(newread, 1);
|
||||
}
|
||||
|
||||
// Find the mean and mode
|
||||
double mean = sum / (double) median.size();
|
||||
double finalMode = getBestKey(mode, median);
|
||||
|
||||
// Find the median
|
||||
Collections.sort(median);
|
||||
double finalMedian;
|
||||
if(median.size() % 2 == 0 && median.size() > 2) {
|
||||
int center = (median.size() / 2) - 1;
|
||||
finalMedian = (median.get(center) + median.get(center + 1)) / 2.0;
|
||||
} else
|
||||
finalMedian = median.get(median.size() / 2);
|
||||
|
||||
return "" + properRound(mean) + " " + properRound(finalMedian) + " " + properRound(finalMode);
|
||||
}
|
||||
|
||||
// Formats the string properly, rounds down to 1 decimal always
|
||||
static String properRound(double input) {
|
||||
return "" + (Math.round(input * 10) / 10.0);
|
||||
}
|
||||
|
||||
// In a dictionary, finds the key with the highest value, for mode
|
||||
// Keys are provided from the list aggregated for the median
|
||||
static int getBestKey(Map<Integer, Integer> map, List<Integer> keys) {
|
||||
int curcount = (Integer) 0;
|
||||
int curkey = (Integer) 0;
|
||||
for(Integer key : keys) {
|
||||
if(map.get(key) > curcount) {
|
||||
curcount = map.get(key);
|
||||
curkey = key;
|
||||
}
|
||||
}
|
||||
return curkey;
|
||||
}
|
||||
}
|
||||
6
uil/October 2013 Set/2/java/.idea/misc.xml
generated
Normal file
6
uil/October 2013 Set/2/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 Set/2/java/.idea/modules.xml
generated
Normal file
8
uil/October 2013 Set/2/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$/2.iml" filepath="$PROJECT_DIR$/2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
124
uil/October 2013 Set/2/java/.idea/uiDesigner.xml
generated
Normal file
124
uil/October 2013 Set/2/java/.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
238
uil/October 2013 Set/2/java/.idea/workspace.xml
generated
Normal file
238
uil/October 2013 Set/2/java/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,238 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="fda95ca9-6d47-41ab-b6e4-9fbffb16dd5f" 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="-64511521">
|
||||
<usages-collector id="statistics.lifecycle.project">
|
||||
<counts>
|
||||
<entry key="project.closed" value="2" />
|
||||
<entry key="project.open.time.0" value="1" />
|
||||
<entry key="project.open.time.3" value="1" />
|
||||
<entry key="project.opened" value="2" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.open">
|
||||
<counts>
|
||||
<entry key="dat" value="3" />
|
||||
<entry key="java" value="1" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.open">
|
||||
<counts>
|
||||
<entry key="JAVA" value="1" />
|
||||
<entry key="PLAIN_TEXT" value="3" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.edit">
|
||||
<counts>
|
||||
<entry key="dat" value="364" />
|
||||
<entry key="java" value="850" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.edit">
|
||||
<counts>
|
||||
<entry key="JAVA" value="850" />
|
||||
<entry key="PLAIN_TEXT" value="364" />
|
||||
</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/problem2.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="153">
|
||||
<caret line="9" column="12" selection-start-line="9" selection-start-column="12" selection-end-line="9" selection-end-column="12" />
|
||||
<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/input1.dat" />
|
||||
<option value="$PROJECT_DIR$/input1.dat" />
|
||||
<option value="$PROJECT_DIR$/src/problem2.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="PackagesPane" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="2" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="2" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="2" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="2" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="src" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="Scope" />
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568523728387" />
|
||||
</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="RunManager">
|
||||
<configuration name="problem2" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="problem2" />
|
||||
<module name="2" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.problem2" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="fda95ca9-6d47-41ab-b6e4-9fbffb16dd5f" name="Default Changelist" comment="" />
|
||||
<created>1568523104137</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1568523104137</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
|
||||
<layout>
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25266525" />
|
||||
<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" />
|
||||
<window_info id="UI Designer" order="4" />
|
||||
<window_info id="Capture Tool" order="5" />
|
||||
<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.32939914" />
|
||||
<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="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="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" />
|
||||
<window_info anchor="right" id="Palette" order="3" />
|
||||
<window_info anchor="right" id="Capture Analysis" order="4" />
|
||||
<window_info anchor="right" id="Theme Preview" order="5" />
|
||||
<window_info anchor="right" id="Palette	" order="6" />
|
||||
<window_info anchor="right" id="Maven Projects" order="7" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="VcsContentAnnotationSettings">
|
||||
<option name="myLimit" value="2678400000" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/src/input1.dat">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="51">
|
||||
<caret line="3" column="51" selection-start-line="3" selection-start-column="51" selection-end-line="3" selection-end-column="51" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/input1.dat">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="34">
|
||||
<caret line="2" selection-start-line="2" selection-end-line="2" selection-end-column="143" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/problem2.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="153">
|
||||
<caret line="9" column="12" selection-start-line="9" selection-start-column="12" selection-end-line="9" selection-end-column="12" />
|
||||
<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 Set/2/java/2.iml
Normal file
11
uil/October 2013 Set/2/java/2.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>
|
||||
4
uil/October 2013 Set/2/java/input1.dat
Normal file
4
uil/October 2013 Set/2/java/input1.dat
Normal file
@@ -0,0 +1,4 @@
|
||||
3
|
||||
@coolstuff This tweet will have exactly 81 characters so it is definitely a tweet
|
||||
@funnyman This message is really, really, really, long so it will not be a tweet. No one wants a long tweet cuz ain't nobody got time for that!
|
||||
@sweetbrown I am so awesome that Beyonce quotes me!
|
||||
BIN
uil/October 2013 Set/2/java/out/production/2/problem2.class
Normal file
BIN
uil/October 2013 Set/2/java/out/production/2/problem2.class
Normal file
Binary file not shown.
18
uil/October 2013 Set/2/java/src/problem2.java
Normal file
18
uil/October 2013 Set/2/java/src/problem2.java
Normal file
@@ -0,0 +1,18 @@
|
||||
import static java.lang.System.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class problem2 {
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
205
uil/October 2013 Set/3/input-generator/main.py
Normal file
205
uil/October 2013 Set/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 Set/3/java/.idea/misc.xml
generated
Normal file
6
uil/October 2013 Set/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 Set/3/java/.idea/modules.xml
generated
Normal file
8
uil/October 2013 Set/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 Set/3/java/.idea/workspace.xml
generated
Normal file
198
uil/October 2013 Set/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 Set/3/java/3.iml
Normal file
11
uil/October 2013 Set/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 Set/3/java/src/problem3.java
Normal file
19
uil/October 2013 Set/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");
|
||||
}
|
||||
|
||||
}
|
||||
254
uil/UIL.md
Normal file
254
uil/UIL.md
Normal file
@@ -0,0 +1,254 @@
|
||||
# UIL Eligibility Packet
|
||||
|
||||
## Question 1
|
||||
|
||||
This can be guessed on pretty easily by analyzing the magnitudes of the powers. Every number here is within a mildly close range of eachother, and the highest numbers have some of the *lowest* powers, so we can assume that the one with the highest power will be the largest when evaluated.
|
||||
|
||||
# Question 2
|
||||
|
||||
This is simple String and Integer addition.
|
||||
|
||||
`3 + 4 + "Hi" + 3 + 4 = "7Hi34"`
|
||||
|
||||
**Remember:** Left to right, Integer + String converts to String, no kind of math involved once integer is converted to String.
|
||||
|
||||
## Question 3
|
||||
|
||||
Super simple math.
|
||||
`3 + (7 + 3) = 13`
|
||||
|
||||
## Question 4
|
||||
|
||||
This one deals with integer division.
|
||||
|
||||
```
|
||||
27 / 2 = 13
|
||||
13 / 2 = 6
|
||||
6 / 2 = 3
|
||||
3 / 2 = 1
|
||||
! 1 / 2 = 0
|
||||
Output: 27
|
||||
```
|
||||
|
||||
Program flow should be analyzed carefully at the start and end as the output will include the first, then it will divide, and then the block ends and revaluates the expression `x > 0`.
|
||||
|
||||
This means that the output will contain the first but not the last phase of the `x` variable.
|
||||
|
||||
## Question 5
|
||||
|
||||
This is another one of those painstaking problems where you have to verify the method without knowing it's purpose: making it a thousand times harder to trust your calculated answer.
|
||||
|
||||
The for loop operates on every index in the String up the center, which ends up being `5` (`10 / 2 = 5`).
|
||||
|
||||
For each index in the String being operated upon, the String `t` has the index being accessed and the last index in the String `s` added (always `e`).
|
||||
|
||||
```
|
||||
0 => He
|
||||
1 => oe
|
||||
2 => we
|
||||
3 => de
|
||||
4 => ye
|
||||
```
|
||||
|
||||
The final output for this problem is `Heoewedeye`.
|
||||
|
||||
## Question 6
|
||||
|
||||
This one requires prior knowledge of `Arrays.fill`.
|
||||
|
||||
**Spoiler:** It's super easy.
|
||||
|
||||
`Arrays.fill(array, start, stop, val)` simply places the value in the array specified from start to stop (left only inclusive).
|
||||
|
||||
Since the specified range is `[2, 3)`, only one 4 is placed at index 2.
|
||||
|
||||
The final array looks like `[0, 0, 4, 0, 0]`
|
||||
|
||||
## Question 7
|
||||
|
||||
This is just pretty awful parantheses aside from the initial solving.
|
||||
|
||||
```
|
||||
!(!(!(...)))
|
||||
!true || !false && !false
|
||||
false || true && true
|
||||
true && true
|
||||
true
|
||||
!(!(!(true)))
|
||||
!(!(false))
|
||||
!(true)
|
||||
|
||||
```
|
||||
|
||||
## Question 8
|
||||
## Question 9
|
||||
## Question 10
|
||||
## Question 11
|
||||
## Question 12
|
||||
## Question 13
|
||||
## Question 14
|
||||
## Question 15
|
||||
## Question 16
|
||||
## Question 17
|
||||
|
||||
First parameter is the number, second is the base.
|
||||
|
||||
Remember for 123<sub>4</sub>, the maximum values for each digit in order from left-to-right (ending on the right), with the number it's used to build (right * 4 = left) would be...
|
||||
|
||||
```
|
||||
n(n/4) - 256(64) - 64(16) - 16(4) - 4(1).
|
||||
```
|
||||
|
||||
So to build 123 <sub>4</sub>, `123 - 64 - 48 - 8 - 3 = 0`.
|
||||
|
||||
And to build 234 <sub>5</sub>, `234 - 125 - 100 - 5 - 4`.
|
||||
|
||||
## Question 18
|
||||
|
||||
Notice that the for loops loop over usually, but use `mat.length` instead of `mat.length-1`. Major mistake which results in a `OutOfBoundsException` to be raised.
|
||||
|
||||
## Question 19 - 21
|
||||
|
||||
Class A has a couple of interesting operators and distinctions that make it a difficult problem to diagnose.
|
||||
|
||||
The constructor starts off by setting `int n` equal to itself after using the (pre) increment operator.
|
||||
|
||||
Class A starts by instantiating a `protected int` primitive and then, while inside the constructor, uses the pre-increment operator.
|
||||
|
||||
Additionally, since this is a class, all objects in `class scope` are given a `default value`, which is different to `local scope`.
|
||||
|
||||
In the end, `n` in the `A` class will always equal 1.
|
||||
|
||||
### Question 19
|
||||
|
||||
*Thanks Mr. Smith for explaining this one better so I could properly understand it.*
|
||||
|
||||
Question 19 makes the user create a new `B` object of type `A`, which is an important distinction as if it was instantiated as type `B`, `getN` would still be accessible - however as type `A`, it is not.
|
||||
|
||||
At compile time, it is evaluated for
|
||||
|
||||
### Question 20
|
||||
|
||||
The pre-increment operator and being in class scope means that `n` will be equal to 1. `toString()` returns `n` in `String` type.
|
||||
|
||||
### Question 21
|
||||
|
||||
Class `B` is similar to the `A` class, and ends up using the `super()` operator. After `this.n` is equal to 1 as usual, `int n` (local constructor scope) is added to `this.n`.
|
||||
|
||||
It is important to understand local/class scope, the `+=` assignment operator, and how `toString()` works.
|
||||
|
||||
## Question 22 - 23
|
||||
|
||||
Another complicated setup, but at least it's based on the same output.
|
||||
|
||||
`String.lastIndexOf("#")` will return the index of the last `#` in the 21 character long `s` String. This index is `19`.
|
||||
|
||||
The `fTwo` method takes two parameters and essentially combines to substrings of everything but that one `#` at index 19.
|
||||
|
||||
The most complicated part of this is that `fOne` and `fTwo` return eachother recursively.
|
||||
|
||||
Check the final else-statement (the first to run if you check based on the first initial input).
|
||||
|
||||
It returns (recursively) the output of `fOne(fTwo(s, s.lastIndexOf("#")))`, which could go on recursively forever, but with careful analysis you'll see this does not happen.
|
||||
|
||||
If the first `#` in a String is the last one, then it'll return the String like that.
|
||||
|
||||
If the String's length is even, then it will recursively return `fOne(fTwo(s, s.indexOf("#")))`.
|
||||
|
||||
Otherwise, it will recursively return `fOne(fTwo(s, s.lastIndexOf("#")))`, as mentioned above.
|
||||
|
||||
### Question 22
|
||||
|
||||
Let's diagnose the output for real and see what is really going on.
|
||||
|
||||
```
|
||||
1 => H#i#t#h#i#s#i#s#f#u#n
|
||||
2 => H#i#t#h#i#s#i#s#f#un
|
||||
3 => Hi#t#h#i#s#i#s#f#un
|
||||
4 => Hi#t#h#i#s#i#s#fun
|
||||
5 => Hit#h#i#s#i#s#fun
|
||||
6 => Hit#h#i#s#i#sfun
|
||||
7 => Hit#h#i#s#isfun
|
||||
8 => Hith#i#s#isfun
|
||||
9 => Hith#i#sisfun
|
||||
10 => Hithi#sisfun
|
||||
```
|
||||
|
||||
On the tenth iteration, the String is finally left with only a single `#`.
|
||||
|
||||
The final string output is equal to `Hithi#sisfun`.
|
||||
|
||||
### Question 23
|
||||
|
||||
This one is rather easy as well, but it requires the output of `22` to continue, as well as a bit of knowledge of Regex.
|
||||
|
||||
The Regex pattern `[aeiou]` simply matches against any one vowel in a row. `String.split` is also pretty simply, creating a String array made out of the string that is broken into pieces based on the matching regex pattern.
|
||||
|
||||
To solve this, all we have to do is identify vowels in `Hithi#sisfun` and mark them out.
|
||||
|
||||
`H[i]th[i]#s[i]sf[u]n`, with brackets around the sections that will be deleted and used to split apart the String.
|
||||
|
||||
The final String array that is returned will be `["H", "th", "#s", "sf", "n"]`.
|
||||
|
||||
## Question 24
|
||||
|
||||
Pretty easy; from left to right `3 + 4 = 7`, and then it's converted to a String, so you add 7, 3 and 7 to make `7737`.
|
||||
|
||||
## Question 25
|
||||
|
||||
This is a rather simple regex pattern, but they all look like insane spaghetti initially. We should note, that since this isn't shown in Java, escaping is done using a single `\` instead of `\\`!
|
||||
|
||||
To better explain, see the code below.
|
||||
|
||||
```java
|
||||
"hello.world".split("\\.")
|
||||
```
|
||||
|
||||
The regex pattern in text that is universally understood would be seen as `\.`, which matches against a single period (dot), and not a *escaped backslash* and a `.` metacharacter.
|
||||
|
||||
This is minor, but I believe it should be properly explained.
|
||||
|
||||
---
|
||||
|
||||
To start understanding the pattern, we should break it apart.
|
||||
|
||||
`^\w{1,}@\w{1,}\.[a-z]{2,3}$`
|
||||
|
||||
`^` is a anchor, showing the start of the String. This is reciprocated at the end with a `$` ending anchor.
|
||||
|
||||
`\w{1,}` matches against any `word` character (alphanumeric or underscore, essentially alphabet, digits or a underscore, case insensitive). It matches against 1 or more, but at least 1. This portion of the pattern is equal to `\w+`.
|
||||
|
||||
`@` matches a single `@` character. We should take a moment to note that the sections before and this match these these kinds of emails:
|
||||
|
||||
```
|
||||
jgu6oaouih23_6@
|
||||
d9hi@
|
||||
i_3@
|
||||
f@
|
||||
```
|
||||
|
||||
but not these
|
||||
|
||||
```
|
||||
@
|
||||
^35a@
|
||||
@
|
||||
```
|
||||
|
||||
(must match 1 character minimum, no special characters other than underscore, no whitespace)
|
||||
|
||||
`\w{1,}\.` matches the same word character in a sequence at minimum 1 character long, and then a dot character (`\.`, not the metacharacter `.`).
|
||||
|
||||
`[a-z]{2, 3}$` matches a sequence of lowercase letters with a length of 2 or 3. The `$` denotes the ending anchor as specified earlier.
|
||||
|
||||
So in summary, the regex pattern matches a sequence of word characters, a `@` symbol, another sequence of word characters, a period, and then 2-3 lowercase letters. This is quite obviously a generate specification for an email (which allows underscores). The 2-3 lowercase letters only allows two or three letter domain extensions (`.com`, `.gov`, `.me` but not `.photography`, `.online`)
|
||||
|
||||
## Question 26
|
||||
|
||||
This is a rather long problem, so let's split it up into the patrs.
|
||||
|
||||
### Class X
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user