Last active
March 11, 2022 14:14
-
-
Save changtimwu/01935dba8948ac01ba684d32680a9d02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Question source: https://tw.news.yahoo.com/%E5%90%B3%E6%B7%A1%E5%A6%82%E6%9B%AC%E5%A5%B3%E5%85%92%E5%9C%8B-%E6%95%B8%E5%AD%B8%E8%80%83%E9%A1%8C-%E9%99%84%E4%B8%AD%E7%88%B8%E7%9C%8B%E5%AE%8C%E4%B8%8D%E6%83%B3%E8%A7%A3%E7%AD%94-%E5%B0%8F%E5%AD%A9%E9%80%A3%E9%A1%8C%E7%9B%AE%E9%83%BD%E7%9C%8B%E4%B8%8D%E6%87%82-050445949.html | |
from itertools import product | |
def validate_rule(mp,fp,mn,fn): | |
return (mp+fp)<(mn+fn) and mp>mn and mn>fn and fp>0 | |
def solution(): | |
for [mp,fp,mn,fn] in product( *[range(0,17)] * 4): | |
if (mp+fp+mn+fn)!=16: continue | |
#print(f"{mp} {fp} {mn} {fn}") | |
if validate_rule(mp,fp,mn,fn): | |
if validate_rule(mp-1,fp,mn,fn): | |
print("I'm a male physicist.") | |
elif validate_rule(mp,fp-1,mn,fn): | |
print("I'm a female physicist.") | |
elif validate_rule(mp,fp,mn-1,fn): | |
print("I'm a male nurse.") | |
elif validate_rule(mp,fp,mn,fn-1): | |
print("I'm a female nurse.") | |
else: | |
print("I'm not there.") | |
solution() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment