Advertisement
GalinaKG

Advent of code - Day 3 - Second task

Dec 3rd, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2. duplicate_chars = []
  3. total_sum = 0
  4. counter = 1
  5.  
  6. with open("text", "r") as input_data:
  7.     for line in input_data:
  8.         if counter == 1:
  9.             first_line = line
  10.         if counter == 2:
  11.             second_line = line
  12.         if counter == 3:
  13.             temporary_chars = []
  14.             third_line = line
  15.             for ch in first_line:
  16.                 if ch in second_line and ch in third_line and ch not in temporary_chars and ch != "\n":
  17.                     temporary_chars.append(ch)
  18.             duplicate_chars.extend(temporary_chars)
  19.             counter = 0
  20.         counter += 1
  21.  
  22. for ch in duplicate_chars:
  23.     total_sum += alphabet.index(ch) + 1
  24.  
  25. print(total_sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement