Created
October 1, 2015 20:40
-
-
Save aldraco/8864ee2566b487624b00 to your computer and use it in GitHub Desktop.
compare points problem on codeeval
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
import sys | |
test_cases = open(sys.argv[1], 'r') | |
def north_south(src, dest): | |
if src > dest: | |
return "S" | |
elif src < dest: | |
return "N" | |
else: | |
return "" | |
def east_west(src, dest): | |
if src > dest: | |
return "W" | |
elif src < dest: | |
return "E" | |
else: | |
return "" | |
for test in test_cases: | |
#ignore if test is an empty line | |
points = test.strip().split(' ') | |
bob, viewpoint = (points[0], points[1]), (points[2], points[3]) | |
print (north_south(bob[0], viewpoint[0]) + east_west(bob[1], viewpoint[1])) or 'here' | |
test_cases.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't feel this is very Pythonic. I originally had the function defs lower in the file, but the program complained that it didn't know what 'north_south' was so clearly they aren't hoisted like in JS?
Also, the two functions are so similar they should be re-written to something DRYer.