|
123456789101112131415161718192021222324252627 |
- from string import ascii_letters
-
- def split_line(line):
- line_length = len(line)
- section_length = line_length//2
- first, second = line[:section_length], line[section_length:]
- return first, second
-
- def main():
- with open("input3.txt", "r") as file:
- inlines = file.readlines()
-
- lines = [(split_line(line)) for line in inlines]
-
- rucksacks = [(set(first), set(second)) for (first, second) in lines]
-
- values = []
- for sack in rucksacks:
- first, second = sack
- common_item = list(first.intersection(second))[0]
- values.append(ascii_letters.index(common_item)+1)
-
- print(sum(values))
-
-
- if __name__ == "__main__":
- main()
|