Created
November 4, 2017 00:05
-
-
Save ShaneRich5/3ac1a1d7b761d1293703d1a696f12482 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def sum_two(a, b): | |
return int(a) + int(b) | |
def compare_versions(version_a, version_b): | |
a = map(int, version_a.split('.')) | |
b = map(int, version_b.split('.')) | |
first_a, first_b = int(a[0]), int(b[0]) | |
# check if a release number is greater | |
if first_a > first_b: | |
return 1 | |
elif first_a < first_b: | |
return -1 | |
total_a = reduce(sum_two, a) | |
total_b = reduce(sum_two, b) | |
if total_a == first_a and total_b == first_b: | |
if len(a) > len(b): | |
return 1 | |
else: | |
return -1 | |
elif total_a > first_a and total_b == first_b: | |
return 1 | |
if total_a == first_a and total_b > first_b: | |
return -1 | |
print version_a, version_b | |
return compare_versions('.'.join(map(str, a[1:])), '.'.join(map(str, b[1:]))) | |
def answer(l): | |
l.sort(compare_versions) | |
return l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment