123456789101112131415161718192021222324252627282930313233343536 |
- from string import ascii_letters
-
- DEBUG=False
-
- def debug(*args):
- if DEBUG:
- print(args)
-
- def main():
- with open("input3.txt", "r") as file:
- inlines = [line.strip() for line in file.readlines()]
-
- groups = []
-
- total_elves = len(inlines)
-
- i,j,k = 0,1,2
-
- while i < total_elves:
- groups.append([inlines[i], inlines[j], inlines[k]])
- i, j, k = i+3, j+3, k+3
-
- values = []
- for group in groups:
- debug(group)
- first, second, third = [set(elf) for elf in group]
- debug(first, second, third)
- debug(first & second & third)
- common_item = list(first & second & third)[0]
- values.append(ascii_letters.index(common_item)+1)
-
- print(sum(values))
-
-
- if __name__ == "__main__":
- main()
|