Week1.
This commit is contained in:
parent
0560f81bd3
commit
aa01ecd3e4
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
|
@ -1,22 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="9">
|
||||
<item index="0" class="java.lang.String" itemvalue="pandas" />
|
||||
<item index="1" class="java.lang.String" itemvalue="dumbeval" />
|
||||
<item index="2" class="java.lang.String" itemvalue="scipy" />
|
||||
<item index="3" class="java.lang.String" itemvalue="tensorflow" />
|
||||
<item index="4" class="java.lang.String" itemvalue="scikit-learn" />
|
||||
<item index="5" class="java.lang.String" itemvalue="PyYAML" />
|
||||
<item index="6" class="java.lang.String" itemvalue="pyzmq" />
|
||||
<item index="7" class="java.lang.String" itemvalue="numpy" />
|
||||
<item index="8" class="java.lang.String" itemvalue="pubeval" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -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="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
<component name="NodePackageJsonFileManager">
|
||||
<packageJsonPaths />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/look_up.py.iml" filepath="$PROJECT_DIR$/.idea/look_up.py.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,169 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="f9135955-8de7-4fe3-8ad8-42bcb9ec775e" name="Default Changelist" comment="" />
|
||||
<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="CoverageDataManager">
|
||||
<SUITE FILE_PATH="coverage/look_up_py$look_up.coverage" NAME="look_up Coverage Results" MODIFIED="1566901041469" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf>
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/look_up.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="397">
|
||||
<caret line="89" column="26" lean-forward="true" selection-start-line="89" selection-start-column="26" selection-end-line="89" selection-end-column="26" />
|
||||
</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$/look_up.py" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds">
|
||||
<option name="x" value="715" />
|
||||
<option name="y" value="91" />
|
||||
<option name="width" value="895" />
|
||||
<option name="height" value="911" />
|
||||
</component>
|
||||
<component name="ProjectView">
|
||||
<navigator proportions="" version="1">
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="look_up.py" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="look_up.py" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="Scope" />
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
|
||||
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
|
||||
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
|
||||
</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="look_up" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="look_up.py" />
|
||||
<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$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/look_up.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.look_up" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="f9135955-8de7-4fe3-8ad8-42bcb9ec775e" name="Default Changelist" comment="" />
|
||||
<created>1566900410249</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1566900410249</updated>
|
||||
<workItem from="1566900414128" duration="1343000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="1343000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="715" y="91" width="895" height="911" extended-state="0" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Favorites" side_tool="true" />
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.09026964" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Database Changes" />
|
||||
<window_info anchor="bottom" id="Version Control" />
|
||||
<window_info anchor="bottom" id="Python Console" />
|
||||
<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 active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32967034" />
|
||||
<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="SciView" />
|
||||
<window_info anchor="right" id="Database" />
|
||||
<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="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/look_up.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="397">
|
||||
<caret line="89" column="26" lean-forward="true" selection-start-line="89" selection-start-column="26" selection-end-line="89" selection-end-column="26" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
|
@ -1,90 +0,0 @@
|
|||
table =\
|
||||
{
|
||||
'O-': {
|
||||
'O-': True,
|
||||
'O+': True,
|
||||
'A-': True,
|
||||
'A+': True,
|
||||
'B-': True,
|
||||
'B+': True,
|
||||
'AB-': True,
|
||||
'AB+': True
|
||||
},
|
||||
'O+': {
|
||||
'O-': False,
|
||||
'O+': True,
|
||||
'A-': False,
|
||||
'A+': True,
|
||||
'B-': False,
|
||||
'B+': True,
|
||||
'AB-': False,
|
||||
'AB+': True
|
||||
},
|
||||
'A-': {
|
||||
'O-': False,
|
||||
'O+': False,
|
||||
'A-': True,
|
||||
'A+': True,
|
||||
'B-': False,
|
||||
'B+': False,
|
||||
'AB-': True,
|
||||
'AB+': True
|
||||
},
|
||||
'A+': {
|
||||
'O-': False,
|
||||
'O+': False,
|
||||
'A-': False,
|
||||
'A+': True,
|
||||
'B-': False,
|
||||
'B+': False,
|
||||
'AB-': False,
|
||||
'AB+': True
|
||||
},
|
||||
'B-': {
|
||||
'O-': False,
|
||||
'O+': False,
|
||||
'A-': False,
|
||||
'A+': False,
|
||||
'B-': True,
|
||||
'B+': True,
|
||||
'AB-': True,
|
||||
'AB+': True
|
||||
},
|
||||
'B+': {
|
||||
'O-': False,
|
||||
'O+': False,
|
||||
'A-': False,
|
||||
'A+': False,
|
||||
'B-': False,
|
||||
'B+': True,
|
||||
'AB-': False,
|
||||
'AB+': True
|
||||
},
|
||||
'AB-': {
|
||||
'O-': False,
|
||||
'O+': False,
|
||||
'A-': False,
|
||||
'A+': False,
|
||||
'B-': False,
|
||||
'B+': False,
|
||||
'AB-': True,
|
||||
'AB+': True
|
||||
},
|
||||
'AB+': {
|
||||
'O-': False,
|
||||
'O+': False,
|
||||
'A-': False,
|
||||
'A+': False,
|
||||
'B-': False,
|
||||
'B+': False,
|
||||
'AB-': False,
|
||||
'AB+': True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def look_up(donor, rec):
|
||||
return table[donor][rec]
|
||||
|
||||
|
||||
print(look_up('A-', 'O-'))
|
123
week1.py
Normal file
123
week1.py
Normal file
|
@ -0,0 +1,123 @@
|
|||
import itertools
|
||||
from enum import unique, Enum
|
||||
|
||||
|
||||
@unique
|
||||
class BloodType(Enum):
|
||||
O_NEGATIVE = (0, 0, 0) # (a, b, sign)
|
||||
O_POSITIVE = (0, 0, 1)
|
||||
A_NEGATIVE = (1, 0, 0)
|
||||
A_POSITIVE = (1, 0, 1)
|
||||
B_NEGATIVE = (0, 1, 0)
|
||||
B_POSITIVE = (0, 1, 1)
|
||||
AB_NEGATIVE = (1, 1, 0)
|
||||
AB_POSITIVE = (1, 1, 1)
|
||||
|
||||
|
||||
def blood_cell_compatibility_lookup(recipient: BloodType, donor: BloodType) -> bool:
|
||||
"""
|
||||
https://en.wikipedia.org/wiki/Blood_type#Red_blood_cell_compatibility
|
||||
"""
|
||||
return {
|
||||
BloodType.O_NEGATIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: False,
|
||||
BloodType.A_NEGATIVE: False,
|
||||
BloodType.A_POSITIVE: False,
|
||||
BloodType.B_NEGATIVE: False,
|
||||
BloodType.B_POSITIVE: False,
|
||||
BloodType.AB_NEGATIVE: False,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.O_POSITIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: True,
|
||||
BloodType.A_NEGATIVE: False,
|
||||
BloodType.A_POSITIVE: False,
|
||||
BloodType.B_NEGATIVE: False,
|
||||
BloodType.B_POSITIVE: False,
|
||||
BloodType.AB_NEGATIVE: False,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.A_NEGATIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: False,
|
||||
BloodType.A_NEGATIVE: True,
|
||||
BloodType.A_POSITIVE: False,
|
||||
BloodType.B_NEGATIVE: False,
|
||||
BloodType.B_POSITIVE: False,
|
||||
BloodType.AB_NEGATIVE: False,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.A_POSITIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: True,
|
||||
BloodType.A_NEGATIVE: True,
|
||||
BloodType.A_POSITIVE: True,
|
||||
BloodType.B_NEGATIVE: False,
|
||||
BloodType.B_POSITIVE: False,
|
||||
BloodType.AB_NEGATIVE: False,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.B_NEGATIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: False,
|
||||
BloodType.A_NEGATIVE: False,
|
||||
BloodType.A_POSITIVE: False,
|
||||
BloodType.B_NEGATIVE: True,
|
||||
BloodType.B_POSITIVE: False,
|
||||
BloodType.AB_NEGATIVE: False,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.B_POSITIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: True,
|
||||
BloodType.A_NEGATIVE: False,
|
||||
BloodType.A_POSITIVE: False,
|
||||
BloodType.B_NEGATIVE: True,
|
||||
BloodType.B_POSITIVE: True,
|
||||
BloodType.AB_NEGATIVE: False,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.AB_NEGATIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: False,
|
||||
BloodType.A_NEGATIVE: True,
|
||||
BloodType.A_POSITIVE: False,
|
||||
BloodType.B_NEGATIVE: True,
|
||||
BloodType.B_POSITIVE: False,
|
||||
BloodType.AB_NEGATIVE: True,
|
||||
BloodType.AB_POSITIVE: False
|
||||
},
|
||||
BloodType.AB_POSITIVE: {
|
||||
BloodType.O_NEGATIVE: True,
|
||||
BloodType.O_POSITIVE: True,
|
||||
BloodType.A_NEGATIVE: True,
|
||||
BloodType.A_POSITIVE: True,
|
||||
BloodType.B_NEGATIVE: True,
|
||||
BloodType.B_POSITIVE: True,
|
||||
BloodType.AB_NEGATIVE: True,
|
||||
BloodType.AB_POSITIVE: True
|
||||
},
|
||||
}[recipient][donor]
|
||||
|
||||
|
||||
def blood_cell_compatibility_boolean(recipient: BloodType, donor: BloodType) -> bool:
|
||||
(ra, rb, rs), (da, db, ds) = recipient.value, donor.value
|
||||
|
||||
return (ra or not da) and (rb or not db) and (rs or not ds)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
green = 0
|
||||
red = 0
|
||||
for recipient, donor in itertools.product(BloodType, repeat=2):
|
||||
lookup = blood_cell_compatibility_lookup(recipient, donor)
|
||||
boolean = blood_cell_compatibility_boolean(recipient, donor)
|
||||
if lookup == boolean:
|
||||
green += 1
|
||||
else:
|
||||
print(f"'{BloodType(donor).name} -> {BloodType(recipient).name}' should be {lookup}.")
|
||||
red += 1
|
||||
print("Green:", green)
|
||||
print("Red :", red)
|
Loading…
Reference in New Issue
Block a user