Didn't get very far with hw5

This commit is contained in:
2018-02-17 00:04:24 -08:00
parent ee8f2c16e2
commit e6715f3686
4 changed files with 157 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.5" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.6" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">

View File

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

View File

@@ -11,20 +11,45 @@
</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>
<file leaf-file-name="hw2.py" pinned="false" current-in-tab="true">
<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="1548">
<caret line="86" column="31" lean-forward="true" selection-start-line="86" selection-start-column="31" selection-end-line="86" selection-end-column="31" />
<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">
@@ -39,6 +64,7 @@
<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>
@@ -49,10 +75,10 @@
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="772" />
<option name="y" value="1428" />
<option name="width" value="1400" />
<option name="height" value="1000" />
<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">
@@ -77,6 +103,16 @@
<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>
@@ -88,7 +124,7 @@
<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$/temp.py" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/HW 5/hw5.py" />
<property name="restartRequiresConfirmation" value="false" />
</component>
<component name="RunDashboard">
@@ -103,49 +139,26 @@
</list>
</option>
</component>
<component name="RunManager" selected="Python.HW 2">
<configuration name="HW 2" type="PythonConfigurationType" factoryName="Python" singleton="true">
<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="/usr/bin/python3" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/HW 2" />
<option name="IS_MODULE_SDK" value="false" />
<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 2/hw2.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>
<configuration name="test" 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="/usr/bin/python3" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<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$/temp.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>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="Python.HW 2" />
<item index="1" class="java.lang.String" itemvalue="Python.test" />
</list>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
@@ -164,28 +177,27 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="26" y="1080" width="2538" height="1444" extended-state="6" />
<editor active="true" />
<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.47786948" sideWeight="0.5" order="7" 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.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.13715415" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<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.39984995" sideWeight="0.5" order="8" 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="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="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="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="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>
@@ -231,29 +243,43 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file:///usr/lib/python3.5/timeit.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="288">
<caret line="129" column="0" lean-forward="false" selection-start-line="129" selection-start-column="0" selection-end-line="129" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/temp.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="17" column="24" lean-forward="true" selection-start-line="17" selection-start-column="24" selection-end-line="17" selection-end-column="24" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/HW 2/hw2.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1548">
<caret line="86" column="31" lean-forward="true" selection-start-line="86" selection-start-column="31" selection-end-line="86" selection-end-column="31" />
<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,66 @@
from time import time
from random import randint
def generate_polynomials(k_input):
n = 2 ** k_input
left = [randint(0, 10) for _ in range(n)]
right = [randint(0, 10) for _ in range(n)]
return left, right
def iterative_poly_solver(left_coefficients, right_coefficients):
result_coefficients = [0 for _ in range(len(left_coefficients) + len(right_coefficients) - 1)]
for left_index, left_val in enumerate(left_coefficients):
for right_index, right_val in enumerate(right_coefficients):
result_coefficients[left_index + right_index] = left_val * right_val + result_coefficients[left_index + right_index]
return result_coefficients
def recursive_poly_solver(left_coefficients, right_coefficients):
if len(left_coefficients) == 1 and len(right_coefficients) == 1:
return [left_coefficients[0] * right_coefficients[0]]
halfway = len(left_coefficients) // 2
left_lower_half = left_coefficients[:halfway]
left_higher_half = left_coefficients[halfway:]
right_lower_half = right_coefficients[:halfway]
right_higher_half = right_coefficients[halfway:]
sum_low_high_left = [0 for _ in range(len(left_lower_half))]
sum_low_high_right = [0 for _ in range(len(right_lower_half))]
for i in range(len(left_lower_half)):
sum_low_high_left[i] = left_lower_half[i] + left_higher_half[i]
sum_low_high_right[i] = right_lower_half[i] + right_lower_half[i]
low_left_low_right_multiply = recursive_poly_solver(left_lower_half, right_lower_half)
sums_multiple = recursive_poly_solver(sum_low_high_left, sum_low_high_right)
high_left_high_right_multiply = recursive_poly_solver(left_higher_half, right_higher_half)
combined = [0 for _ in range(len(left_coefficients) + len(right_coefficients) - 1)]
for i in range(len(left_coefficients) - 1):
combined[i] += low_left_low_right_multiply[i]
combined[i + halfway] += sums_multiple[i] - low_left_low_right_multiply[i] - high_left_high_right_multiply[i]
combined[i + 2 * halfway] += high_left_high_right_multiply[i]
return combined
if __name__ == '__main__':
for i in range(20):
left, right = generate_polynomials(i)
start = time()
iterative_poly_solver(left, right)
print("%s\t%s" % (2 ** i, time()-start))
# for i in range(10):
# left, right = generate_polynomials(i)
# print(recursive_poly_solver(left[0], right[1]))