Dojnaz

AoC Day2

Dec 17th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from collections import Counter
  2.  
  3. #Läs fil och rengör den...
  4. myfile = open('input.txt', 'r')
  5. contents = myfile.read().strip().splitlines()
  6. myfile.close()
  7.  
  8. #Del 1
  9.  
  10. #c = 2d array
  11. c = [0, 0]
  12. def p1():
  13.     for i in contents:
  14.         a = [b for i,b in Counter(i).most_common()]
  15.         if 3 in a:
  16.             c[0] += 1
  17.         if 2 in a:
  18.             c[1] += 1
  19.     return c[0] * c[1]
  20.  
  21.  
  22.    
  23. def p2():
  24.     for i in contents:
  25.         for b in contents:
  26.             diffs = 0
  27.             for y, x in enumerate(i):
  28.                 if x != b[y]:
  29.                     diffs += 1
  30.             if diffs == 1:
  31.                 ans = [x for y, x in enumerate(i) if b[y] == x]
  32.                 return ans
  33.  
  34. print(p1())
  35. print(''.join(p2()))
Advertisement
Add Comment
Please, Sign In to add comment