retyped day2, completed days 3 and 4, modified template
This commit is contained in:
22
day3/part1.py
Normal file
22
day3/part1.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from string import ascii_lowercase
|
||||
|
||||
|
||||
def parse(filename: str) -> list[tuple[str, str]]:
|
||||
with open(filename) as f:
|
||||
return list(map(lambda x: (x[0 : int((len(x) - 1) / 2)], x[int((len(x) - 1) / 2) : -1]), f.readlines()))
|
||||
|
||||
|
||||
def convert(char: str) -> int:
|
||||
return ord(char) - 96 if char in ascii_lowercase else ord(char) - 38
|
||||
|
||||
|
||||
def solve(bagpacks: list[tuple[str, str]]) -> int:
|
||||
return sum(map(convert, [(filter(lambda x: x in bagpack[1], bagpack[0])).__next__() for bagpack in bagpacks]))
|
||||
|
||||
|
||||
def main():
|
||||
print(solve(parse("input")))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user