Advertisement
SimonJkAdamek

AOC day 3

Dec 3rd, 2022
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. errors=0
  4.  
  5. with open("input.txt") as file:
  6.     for line in file:
  7.         s=len(line.strip())//2
  8.         com1, com2 = line[:s], line[s:]
  9.        
  10.         for i in com1:
  11.             if i in com2:
  12.                 if i.isupper():
  13.                     errors+=ord(i)-38
  14.                 else:
  15.                     errors+=ord(i)-96
  16.                 break
  17. print(errors)
  18.        
  19. ##################################################################################################
  20.  
  21. #!/usr/bin/env python3
  22.  
  23. badges=0
  24.  
  25. with open("input.txt") as file:
  26.     text=file.read().split()
  27.    
  28.  
  29. def same(one, two, *three):
  30.     same=set()
  31.     for char in one:
  32. #        if (char in two) and (char in three):
  33.         if char in two:
  34.             same.add(char)
  35.     return(same)
  36.  
  37.  
  38. for i in range(3, len(text)+1, 3):
  39.     one=text[i-3]
  40.     two=text[i-2]
  41.     three=text[i-1]
  42.  
  43.     group=same(same(one,two),same(two,three)).pop()
  44. #    group=same(one, two, three).pop()
  45.     if group.isupper():
  46.         badges+=ord(group)-38
  47.     else:
  48.         badges+=ord(group)-96
  49.        
  50. print(badges)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement