Added missing classes from final year at OSU

This commit is contained in:
2019-06-17 14:04:15 -07:00
parent 8fa1ffb1b0
commit c717a0316f
166 changed files with 653934 additions and 308 deletions

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/CS 325 - Analysis of Algorithms.iml" filepath="$PROJECT_DIR$/.idea/CS 325 - Analysis of Algorithms.iml" />
</modules>
</component>
</project>

View File

@@ -1,285 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="8463bdd4-0c68-42b0-84f5-1c2abf1a6d5f" name="Default" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" 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="CoverageDataManager">
<SUITE FILE_PATH="coverage/CS_325___Analysis_of_Algorithms$test.coverage" NAME="test Coverage Results" MODIFIED="1517016348937" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/CS_325___Analysis_of_Algorithms$HW_5.coverage" NAME="HW 5 Coverage Results" MODIFIED="1518853467198" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/HW 5" />
<SUITE FILE_PATH="coverage/CS_325___Analysis_of_Algorithms$HW_2.coverage" NAME="HW 2 Coverage Results" MODIFIED="1517020025345" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/HW 2" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="hw2.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/HW 2/hw2.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="160">
<caret line="107" column="56" lean-forward="false" selection-start-line="107" selection-start-column="56" selection-end-line="107" selection-end-column="56" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="hw4.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/HW 4/hw4.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#0#26#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="hw5.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/HW 5/hw5.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="0" lean-forward="true" selection-start-line="9" selection-start-column="0" selection-end-line="9" selection-end-column="0" />
<folding>
<element signature="e#0#21#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/temp.py" />
<option value="$PROJECT_DIR$/HW 2/hw2.py" />
<option value="$PROJECT_DIR$/HW 5/hw5.py" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-8" />
<option name="y" value="-8" />
<option name="width" value="2576" />
<option name="height" value="1426" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="CS 325 - Analysis of Algorithms" type="b2602c69:ProjectViewProjectNode" />
<item name="CS 325 - Analysis of Algorithms" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="CS 325 - Analysis of Algorithms" type="b2602c69:ProjectViewProjectNode" />
<item name="CS 325 - Analysis of Algorithms" type="462c0819:PsiDirectoryNode" />
<item name="HW 4" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="CS 325 - Analysis of Algorithms" type="b2602c69:ProjectViewProjectNode" />
<item name="CS 325 - Analysis of Algorithms" type="462c0819:PsiDirectoryNode" />
<item name="HW 5" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/HW 5/hw5.py" />
<property name="restartRequiresConfirmation" value="false" />
</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="HW 5" type="PythonConfigurationType" factoryName="Python" singleton="true">
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/HW 5" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<module name="CS 325 - Analysis of Algorithms" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/HW 5/hw5.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="8463bdd4-0c68-42b0-84f5-1c2abf1a6d5f" name="Default" comment="" />
<created>1516999834836</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1516999834836</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="2576" height="1426" extended-state="6" />
<layout>
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.47753236" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.17629407" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.13710937" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="SciView" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3998477" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="combo" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
</layout>
<layout-to-restore>
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32933232" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.17629407" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.1375494" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="combo" />
<window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="SciView" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.39984995" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
</layout-to-restore>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<default-breakpoints>
<breakpoint type="python-exception">
<properties notifyOnTerminate="true" exception="BaseException">
<option name="notifyOnTerminate" value="true" />
</properties>
</breakpoint>
</default-breakpoints>
<option name="time" value="2" />
</breakpoint-manager>
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/HW 2/hw2.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/lib/python3.5/timeit.py" />
<entry file="file://$PROJECT_DIR$/temp.py" />
<entry file="file://$PROJECT_DIR$/HW 2/hw2.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="160">
<caret line="107" column="56" lean-forward="false" selection-start-line="107" selection-start-column="56" selection-end-line="107" selection-end-column="56" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/HW 4/hw4.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#0#26#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/HW 5/hw5.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="0" lean-forward="true" selection-start-line="9" selection-start-column="0" selection-end-line="9" selection-end-column="0" />
<folding>
<element signature="e#0#21#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

@@ -0,0 +1,9 @@
For insertsort.py and mergesort.py, ensure data.txt is in the same directory, then run:
python3 insertsort.py
python3 mergesort.py
For insertTime.py and mergeTime.py, simply run:
python3 insertTime.py
python3 mergeTime.py

View File

@@ -0,0 +1,3 @@
10 10 9 8 7 6 5 4 3 2 1
3 8 8 8
8 1 3 4 1 4 7 3 5

View File

@@ -0,0 +1,34 @@
from random import randint
from time import time
MIN_INT = 0
MAX_INT = 10000
def insert_sort(data):
for current_value_index in range(1, len(data)):
current = data[current_value_index]
while current_value_index > 0 and data[current_value_index - 1] > current:
data[current_value_index] = data[current_value_index - 1]
current_value_index -= 1
data[current_value_index] = current
return data
if __name__ == "__main__":
start = 5000
step = 1000
n_values = [start + i * step for i in range(10)]
n_generated_list = [[randint(MIN_INT, MAX_INT) for _ in range(n_value)] for n_value in n_values]
print("n_value, time")
for current_list in n_generated_list:
current_length = len(current_list)
start_time = time()
insert_sort(current_list)
print("{}, {}".format(current_length, time() - start_time))

View File

@@ -0,0 +1,41 @@
INPUT_FILENAME = "data.txt"
OUTPUT_FILENAME = "insert.txt"
def insert_sort(data):
for current_value_index in range(1, len(data)):
current = data[current_value_index]
while current_value_index > 0 and data[current_value_index - 1] > current:
data[current_value_index] = data[current_value_index - 1]
current_value_index -= 1
data[current_value_index] = current
return data
if __name__ == "__main__":
output = []
with open(INPUT_FILENAME, "r") as input_file:
file_lines = input_file.readlines()
for line in file_lines:
line = line.strip("\n\r")
line_items = line.split(" ")
data_values = [int(item) for item in line_items[1:]]
output.append(insert_sort(data_values))
with open(OUTPUT_FILENAME, "w") as output_file:
output_last_index = len(output) - 1
for index, line in enumerate(output):
line_string = " ".join([str(value) for value in line])
output_file.write(line_string)
if index != output_last_index:
output_file.write("\n")

View File

@@ -0,0 +1,64 @@
from random import randint
from time import time
MIN_INT = 0
MAX_INT = 10000
def merge_sort(data, top_level=False):
data_length = len(data)
if data_length > 1:
list_midpoint = data_length // 2
left_data = data[:list_midpoint]
left_data_length = len(left_data)
right_data = data[list_midpoint:]
right_data_length = len(right_data)
merge_sort(left_data)
merge_sort(right_data)
left_data_index = 0
right_data_index = 0
final_data_index = 0
while left_data_index < left_data_length and right_data_index < right_data_length:
if left_data[left_data_index] < right_data[right_data_index]:
data[final_data_index] = left_data[left_data_index]
left_data_index += 1
else:
data[final_data_index] = right_data[right_data_index]
right_data_index += 1
final_data_index += 1
while left_data_index < left_data_length:
data[final_data_index] = left_data[left_data_index]
left_data_index += 1
final_data_index += 1
while right_data_index < right_data_length:
data[final_data_index] = right_data[right_data_index]
right_data_index += 1
final_data_index += 1
if top_level:
return data
if __name__ == "__main__":
start = 200000
step = 250000
n_values = [start + i * step for i in range(10)]
n_generated_list = [[randint(MIN_INT, MAX_INT) for _ in range(n_value)] for n_value in n_values]
print("n_value, time")
for current_list in n_generated_list:
current_length = len(current_list)
start_time = time()
merge_sort(current_list, top_level=True)
print("{}, {}".format(current_length, time() - start_time))

View File

@@ -0,0 +1,72 @@
INPUT_FILENAME = "data.txt"
OUTPUT_FILENAME = "merge.txt"
def merge_sort(data, top_level=False):
data_length = len(data)
if data_length > 1:
list_midpoint = data_length // 2
left_data = data[:list_midpoint]
left_data_length = len(left_data)
right_data = data[list_midpoint:]
right_data_length = len(right_data)
merge_sort(left_data)
merge_sort(right_data)
left_data_index = 0
right_data_index = 0
final_data_index = 0
while left_data_index < left_data_length and right_data_index < right_data_length:
if left_data[left_data_index] < right_data[right_data_index]:
data[final_data_index] = left_data[left_data_index]
left_data_index += 1
else:
data[final_data_index] = right_data[right_data_index]
right_data_index += 1
final_data_index += 1
while left_data_index < left_data_length:
data[final_data_index] = left_data[left_data_index]
left_data_index += 1
final_data_index += 1
while right_data_index < right_data_length:
data[final_data_index] = right_data[right_data_index]
right_data_index += 1
final_data_index += 1
if top_level:
return data
if __name__ == "__main__":
output = []
with open(INPUT_FILENAME, "r") as input_file:
file_lines = input_file.readlines()
for line in file_lines:
line = line.strip("\n\r")
line_items = line.split(" ")
item_count = int(line_items[0])
data_values = [int(item) for item in line_items[1:]]
output.append(merge_sort(data_values, top_level=True))
with open(OUTPUT_FILENAME, "w") as output_file:
output_last_index = len(output) - 1
for index, line in enumerate(output):
line_string = " ".join([str(value) for value in line])
output_file.write(line_string)
if index != output_last_index:
output_file.write("\n")

View File

@@ -0,0 +1,7 @@
Ensure data.txt is in the same directory, then run:
python3 stoogesort.py
For stoogeTime, simply run:
python3 stoogeTime.py

View File

@@ -0,0 +1,41 @@
from random import randint
from time import time
MIN_INT = 0
MAX_INT = 10000
def stooge_sort(data, start_index=0, end_index=None):
if end_index is None:
end_index = len(data) - 1
data_length = end_index - start_index
if data[start_index] > data[end_index]:
data[start_index], data[end_index] = data[end_index], data[start_index]
if data_length > 1:
split_point = (end_index - start_index + 1) // 3
stooge_sort(data, 0, end_index - split_point)
stooge_sort(data, start_index + split_point, end_index)
stooge_sort(data, 0, end_index - split_point)
return data
if __name__ == "__main__":
start = 4
step = 1
n_values = [start + i * step for i in range(10)]
n_generated_list = [[randint(MIN_INT, MAX_INT) for _ in range(n_value)] for n_value in n_values]
print("n_value, time")
for current_list in n_generated_list:
current_length = len(current_list)
start_time = time()
stooge_sort(current_list)
print("{}, {}".format(current_length, time() - start_time))

View File

@@ -0,0 +1,48 @@
INPUT_FILENAME = "data.txt"
OUTPUT_FILENAME = "stooge.out"
def stooge_sort(data, start_index=0, end_index=None):
if end_index is None:
end_index = len(data) - 1
data_length = end_index - start_index
if data[start_index] > data[end_index]:
data[start_index], data[end_index] = data[end_index], data[start_index]
if data_length > 1:
split_point = (end_index - start_index + 1) // 3
stooge_sort(data, 0, end_index - split_point)
stooge_sort(data, start_index + split_point, end_index)
stooge_sort(data, 0, end_index - split_point)
return data
if __name__ == "__main__":
output = []
with open(INPUT_FILENAME, "r") as input_file:
file_lines = input_file.readlines()
for line in file_lines:
line = line.strip("\n\r")
line_items = line.split(" ")
item_count = int(line_items[0])
data_values = [int(item) for item in line_items[1:]]
output.append(stooge_sort(data_values))
with open(OUTPUT_FILENAME, "w") as output_file:
output_last_index = len(output) - 1
for index, line in enumerate(output):
line_string = " ".join([str(value) for value in line])
output_file.write(line_string)
if index != output_last_index:
output_file.write("\n")

View File

@@ -0,0 +1,3 @@
To run this program, place the file "shopping.txt" in the same directory, then run
python3 shopping.py

View File

@@ -0,0 +1,61 @@
Test Case 1
Total Price 0
Member Items:
1:
2:
Test Case 2
Total Price 435
Member Items:
1: 3 4 5 6
2: 2 4 5
3: 3 4 6
4: 3 4 5
Test Case 3
Total Price 83
Member Items:
1: 3
2: 2 3
3: 1 2 3
4: 2 3 4
5: 1 2 3 4
6: 1 2 3 4
7: 2 3 5
8: 1 2 3 5
9: 2 3 4 5
10: 1 2 3 4 5
Test Case 4
Total Price 646
Member Items:
1: 1
2: 1
3: 2
4: 1 2
5: 1 5
6: 2 3
7: 7
8: 1 7
9: 10
10: 2 7
11: 1 2 7
12: 2 10
13: 2 3 7
14: 1 2 3 7
15: 7 9
16: 7 10
17: 1 7 10
18: 2 7 9
19: 2 7 10
20: 1 2 7 10
21: 2 3 7 9
22: 2 3 7 10
23: 1 2 3 7 10
24: 7 9 10
25: 2 6 7 10
26: 2 3 5 7 10
27: 2 7 9 10
28: 2 3 6 7 10
29: 1 2 3 6 7 10
30: 2 3 7 9 10

View File

@@ -0,0 +1,131 @@
INPUT_FILE = "shopping.txt"
OUTPUT_FILE = "results.txt"
def shopping_solver(max_individual_weight, shopping_items):
num_items = len(shopping_items["weights"])
# Each element of the table is (z, (a, b)) where z is the max value, and (a, b) are the x and y
# coordinates in the table for the parent that was used to create this value
lookup_table = [[(0, (0, 0)) for _ in range(num_items + 1)] for _ in range(max_individual_weight + 1)]
# Run the solver
for current_weight in range(max_individual_weight + 1):
for current_item in range(num_items + 1):
last_item_index = current_item - 1
if current_weight == 0 or current_item == 0:
lookup_table[current_weight][current_item] = 0, (0, 0)
elif shopping_items["weights"][last_item_index] <= current_weight:
included_weight = current_weight - shopping_items["weights"][last_item_index]
included = shopping_items["prices"][last_item_index] + lookup_table[included_weight][last_item_index][0]
not_included = lookup_table[current_weight][last_item_index][0]
if included > not_included:
lookup_table[current_weight][current_item] = included, (included_weight, last_item_index)
else:
lookup_table[current_weight][current_item] = not_included, (current_weight, last_item_index)
else:
lookup_table[current_weight][current_item] = \
lookup_table[current_weight][last_item_index][0], (current_weight, last_item_index)
# Trace parents to find the path
solved_path = []
last_weight_index, last_item_index = max_individual_weight, num_items
current_weight_index, current_item_index = lookup_table[max_individual_weight][num_items][1]
while [current_weight_index == 0,
current_item_index == 0,
last_weight_index == 0,
last_item_index == 0] != [True, True, True, True]:
if current_item_index != last_item_index and current_weight_index != last_weight_index:
solved_path.append(current_item_index + 1)
last_item_index = current_item_index
last_weight_index = current_weight_index
current_weight_index, current_item_index = lookup_table[current_weight_index][current_item_index][1]
return lookup_table[max_individual_weight][num_items][0], list(reversed(solved_path))
def get_tests_from_file(filename):
tests_from_file = []
with open(filename, "r") as shopping_file:
lines = shopping_file.readlines()
line_index = 0
num_tests = int(lines[line_index])
for test_number in range(num_tests):
current_test = {"items": {"weights": [], "prices": []}, "family": []}
line_index += 1
num_items = int(lines[line_index])
for item_number in range(num_items):
line_index += 1
item = lines[line_index]
item_split = item.split(" ")
current_test["items"]["weights"].append(int(item_split[1]))
current_test["items"]["prices"].append(int(item_split[0]))
line_index += 1
num_family = int(lines[line_index])
for family_number in range(num_family):
line_index += 1
current_test["family"].append(int(lines[line_index]))
tests_from_file.append(current_test)
return tests_from_file
def print_and_save_results(all_testing_results):
output_string = ""
for test_number, current_test in enumerate(all_testing_results):
output_string += "Test Case {}\n".format(test_number + 1)
output_string += "Total Price {}\n".format(current_test[0])
output_string += "Member Items:\n"
for member_number, items in enumerate(current_test[1]):
if items:
output_string += "{}: {}\n".format(member_number + 1, " ".join([str(item) for item in items]) + " ")
else:
output_string += "{}: \n".format(member_number + 1)
output_string += "\n"
print(output_string, end="")
with open(OUTPUT_FILE, "w") as output_file:
output_file.write(output_string)
if __name__ == "__main__":
tests = get_tests_from_file(INPUT_FILE)
all_test_results = []
for test in tests:
test_sum = 0
family_member_items = []
for family_member in test["family"]:
max_value, item_indexes = shopping_solver(family_member, test["items"])
test_sum += max_value
family_member_items.append(item_indexes)
all_test_results.append((test_sum, family_member_items))
print_and_save_results(all_test_results)

View File

@@ -0,0 +1,78 @@
4
2
77 7
66 6
2
5
5
6
32 16
43 12
26 4
50 8
20 3
27 9
4
25
23
21
19
5
1 1
2 1
3 1
2 2
5 5
10
1
2
3
4
5
6
7
8
9
10
10
1 1
4 3
4 3
4 4
5 4
8 6
10 7
9 7
11 8
13 9
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

View File

@@ -0,0 +1,3 @@
To run this program, place the file "act.txt" in the same directory, then run
python3 activity_selection.py

View File

@@ -0,0 +1,23 @@
11
1 1 4
2 3 5
3 0 6
4 5 7
5 3 9
6 5 9
7 6 10
8 8 11
9 8 12
10 2 14
11 12 16
3
3 6 8
1 7 9
2 1 2
6
1 1 5
2 3 6
3 6 10
4 8 11
5 11 15
6 12 15

View File

@@ -0,0 +1,58 @@
INPUT_FILE = "act.txt"
def greedy_activity_selector(activity_set):
activity_num_index = 0
activity_start_index = 1
activity_finish_index = 2
activity_set.sort(key=lambda activity: activity[activity_start_index], reverse=True)
selections = [activity_set[0][activity_num_index]]
comparison_activity_index = 0
for i in range(1, len(activity_set)):
if activity_set[i][activity_finish_index] <= activity_set[comparison_activity_index][activity_start_index]:
selections.append(activity_set[i][activity_num_index])
comparison_activity_index = i
return list(reversed(selections))
def get_activity_sets(input_filename):
file_activity_sets = []
with open(input_filename, "r") as input_file:
lines = input_file.readlines()
last_index = len(lines) - 1
line_index = -1
while line_index != last_index:
current_set = []
line_index += 1
num_activities = int(lines[line_index])
for activity_number in range(num_activities):
line_index += 1
activity = lines[line_index]
activity_split = activity.split(" ")
current_set.append(list((int(value) for value in activity_split)))
file_activity_sets.append(current_set)
return file_activity_sets
if __name__ == "__main__":
activity_sets = get_activity_sets(INPUT_FILE)
for set_number, current_activity_set in enumerate(activity_sets):
selected_activities = greedy_activity_selector(current_activity_set)
print("Set {}".format(set_number + 1))
print("Number of activities selected = {}".format(len(selected_activities)))
print("Activities: {}".format(" ".join([str(activity) for activity in selected_activities])))
print()

View File

@@ -0,0 +1,7 @@
To run this program, place the file with wrestling information in the same directory, then run
python3 wrestler.py filename
An example would be
python3 wrestler.py wrestler.txt

View File

@@ -0,0 +1,116 @@
import argparse
from collections import deque
class Wrestler(object):
def __init__(self, name):
self._name = name
self._rivals = deque()
self._parent = None
self.depth = 0
def __repr__(self):
return "{}: {}".format(self._name, [rival.name for rival in self._rivals])
@property
def name(self):
return self._name
@property
def rivals(self):
return self._rivals
def add_rival(self, rival):
self._rivals.append(rival)
def wrestler_bfs(wrestlers):
seen = set()
bfs_babyfaces = []
bfs_heels = []
for wrestler in wrestlers:
current_wrestlers = deque([wrestler])
while current_wrestlers:
current_wrestler = current_wrestlers.popleft()
if current_wrestler.name not in seen:
seen.add(current_wrestler.name)
wrestlers_to_expand = deque(current_wrestler.rivals)
if current_wrestler.depth % 2 == 0:
should_append = True
for rival_wrestler in wrestlers_to_expand:
if rival_wrestler.name in bfs_babyfaces:
should_append = False
break
if should_append:
bfs_babyfaces.append(current_wrestler.name)
else:
should_append = True
for rival_wrestler in wrestlers_to_expand:
if rival_wrestler.name in bfs_heels:
should_append = False
break
if should_append:
bfs_heels.append(current_wrestler.name)
for rival_wrestler in wrestlers_to_expand:
rival_wrestler.depth = current_wrestler.depth + 1
current_wrestlers += wrestlers_to_expand
return bfs_babyfaces, bfs_heels
def get_wrestler_info_from_file(filename):
found_wrestlers = deque()
found_wrestler_indexes = {}
with open(filename, "r") as input_file:
lines = input_file.readlines()
current_line = 0
file_num_wrestlers = int(lines[current_line])
for i in range(file_num_wrestlers):
current_line += 1
wrestler_name = lines[current_line].strip("\n")
found_wrestlers.append(Wrestler(wrestler_name))
found_wrestler_indexes[wrestler_name] = len(found_wrestlers) - 1
current_line += 1
num_rivalries = int(lines[current_line])
for _ in range(num_rivalries):
current_line += 1
rival_1_name, rival_2_name = lines[current_line].strip("\n").split(" ")
rival_1_index = found_wrestler_indexes[rival_1_name]
rival_2_index = found_wrestler_indexes[rival_2_name]
found_wrestlers[rival_1_index].add_rival(found_wrestlers[rival_2_index])
found_wrestlers[rival_2_index].add_rival(found_wrestlers[rival_1_index])
return found_wrestlers
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Tool to determine which wrestlers are babyfaces or heels")
parser.add_argument("input_filename", help="Filename of wrestler information to use")
args = parser.parse_args()
all_wrestlers = get_wrestler_info_from_file(args.input_filename)
babyfaces, heels = wrestler_bfs(all_wrestlers)
num_wrestlers = len(all_wrestlers)
num_assigned = len(babyfaces) + len(heels)
if num_wrestlers == num_assigned:
print("Yes")
print("Babyfaces: {}".format(" ".join(babyfaces)))
print("Heels: {}".format(" ".join(heels)))
else:
print("No")

View File

@@ -0,0 +1,28 @@
10
A
B
C
D
E
V
W
X
Y
Z
10
A W
A V
A Z
B Z
B Y
C X
D W
E Z
E Y
E W
// Sample Output
Yes possible
Babyfaces : A B C D E
Heels : V W X Y Z

View File

@@ -0,0 +1,16 @@
6
Bear
Maxxx
Killer
Knight
Duke
Samson
6
Bear Samson
Bear Duke
Killer Bear
Samson Duke
Killer Duke
Maxxx Knight
// Impossible

View File

@@ -0,0 +1,18 @@
6
Bear
Maxxx
Killer
Knight
Duke
Samson
5
Bear Samson
Killer Bear
Samson Duke
Killer Duke
Maxxx Knight
// Sample Solution
Yes Possible
Babyfaces: Bear Maxx Duke
Heels: Killer Knight Samson

View File

@@ -0,0 +1,18 @@
5
Ace
Duke
Jax
Biggs
Stone
6
Ace Duke
Ace Biggs
Jax Duke
Stone Biggs
Stone Duke
Biggs Jax
// Sample Output:
Yes
Babyfaces: Ace Jax Stone
Heels: Biggs Duke

View File

@@ -0,0 +1,3 @@
To run this program, place the file bin.txt in the same directory, then run
python3 binpack.py

View File

@@ -0,0 +1,12 @@
3
10
6
5 10 2 5 4 4
20
19
9 10 2 1 7 3 3 3 3 14 6 5 2 8 6 4 6 2 6
10
20
4 4 4 4 4 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6

View File

@@ -0,0 +1,121 @@
from time import time
from collections import deque
from copy import copy
INPUT_FILENAME = "bin.txt"
class BinPacker(object):
def __init__(self, bin_pack_test_case):
self._bin_size = bin_pack_test_case["bin_capacity"]
self._items = deque(list(bin_pack_test_case["items"]))
self._bins = []
self._run_time = 0
def _solve(self):
raise NotImplemented
def solve_and_time(self):
start_time = time() * 1000
self._solve()
self._run_time = (time() * 1000) - start_time
return len(self._bins), self._run_time
class FirstFit(BinPacker):
def _solve(self):
while self._items:
current_item = self._items.popleft()
item_placed = False
for bin_index in range(len(self._bins)):
new_sum = self._bins[bin_index] + current_item
if new_sum <= self._bin_size:
self._bins[bin_index] = new_sum
item_placed = True
break
if not item_placed:
self._bins.append(current_item)
class FirstFitDecreasing(FirstFit):
def _solve(self):
sorted_descending = list(self._items)
sorted_descending.sort(reverse=True)
self._items = deque(sorted_descending)
super(FirstFitDecreasing, self)._solve()
class BestFit(BinPacker):
def _solve(self):
while self._items:
current_item = self._items.popleft()
min_room_left_over = self._bin_size
best_index_sum = None
best_index = None
for bin_index in range(len(self._bins)):
new_sum = self._bins[bin_index] + current_item
bin_difference = self._bin_size - new_sum
if 0 <= bin_difference < min_room_left_over:
best_index = bin_index
best_index_sum = new_sum
min_room_left_over = bin_difference
if best_index is not None:
self._bins[best_index] = best_index_sum
else:
self._bins.append(current_item)
# print(self._bins)
def get_test_cases_from_file(filename):
input_test_cases = []
with open(filename, "r") as input_file:
file_lines = input_file.readlines()
current_line = 0
num_test_cases = int(file_lines[current_line])
for _ in range(num_test_cases):
current_test_case = {}
current_line += 1
current_test_case["bin_capacity"] = int(file_lines[current_line])
current_line += 1
num_items = int(file_lines[current_line])
current_line += 1
items_split = file_lines[current_line].split(" ")
current_test_case["items"] = [int(item_str) for item_str in items_split[:num_items]]
input_test_cases.append(current_test_case)
return input_test_cases
if __name__ == "__main__":
test_cases = get_test_cases_from_file(INPUT_FILENAME)
for test_index, test_case in enumerate(test_cases):
first_fit_num_bins, first_fit_run_time = FirstFit(test_case).solve_and_time()
first_fit_dec_num_bins, first_fit_dec_run_time = FirstFitDecreasing(test_case).solve_and_time()
best_fit_num_bins, best_fit_run_time = BestFit(test_case).solve_and_time()
print("Test Case {} First Fit: {}, {} ms. First Fit Decreasing {}, {} ms. Best Fit: {}, {} ms.".format(
test_index + 1,
first_fit_num_bins, first_fit_run_time,
first_fit_dec_num_bins, first_fit_dec_run_time,
best_fit_num_bins, best_fit_run_time
))