Advertisement
ralig

Advent Of Code 2020 Day 6 Part 2

Dec 6th, 2020
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. from pathlib import Path
  2. path = Path(__file__).parent / "../../input.txt"
  3.  
  4. data = []
  5. with path.open("rt") as f:
  6.     data = f.readlines()
  7.  
  8.  
  9. def findInData(toFind, start):
  10.     lastLine = start
  11.     for x in range(start,len(data)):
  12.         if data[x] == toFind:
  13.             return x
  14.         lastLine = x
  15.     if lastLine == len(data)-1:
  16.         return len(data)
  17.     return False
  18.  
  19. answer = 0
  20.  
  21. first = 0 #first entry in group
  22. last = 0  #last entry in group
  23. last = findInData("\n",first) - 1
  24. all4 = ""
  25.  
  26. while(last != -1):
  27.     data[first] = data[first].replace("\n","")
  28.     for letter in data[first]:
  29.  
  30.         foundCount = 0
  31.         for x in range(first+1, last+1):
  32.             if (letter in data[x]):
  33.                 foundCount += 1
  34.         if foundCount == last-first:
  35.             answer += 1
  36.        
  37.     first = last+2
  38.     last = findInData("\n",first) - 1
  39.        
  40. print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement