Created
December 3, 2022 18:18
-
-
Save gs0510/f3388d5f7d04032d838e8804241413f1 to your computer and use it in GitHub Desktop.
day3 aoc
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
def common(str1, str2,str3: None): | |
if not str3: | |
return sum([ (ord(val)-ord('a')+1) if val.islower() else (ord(val)-ord('A')+27) for val in list(set(str1)&set(str2))]) | |
else: | |
return sum([ (ord(val)-ord('a')+1) if val.islower() else (ord(val)-ord('A')+27) for val in list(set(str1)&set(str2)&set(str3))]) | |
def run1(): | |
data = open('input.txt', 'r').read().split('\n') | |
return sum([common(line[0:(len(line)//2)], line[(len(line)//2):], None) for line in data]) | |
def run2(): | |
data = open('input.txt', 'r').read().split('\n') | |
return sum([common(data[i], data[i+1], data[i+2]) for i in range(0, len(data), 3)]) | |
if __name__ == "__main__": | |
print(run1()) | |
print(run2()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment