Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- entries = []
- with open("6 - input", 'r') as file:
- lines = file.readlines()
- entry = []
- for line in lines:
- if line != "\n":
- entry.append(line.strip("\n"))
- if line == "\n" or line is lines[-1]:
- entry.sort()
- entries.append(entry)
- entry = []
- print(entries)
- concatEntries = []
- for entry in entries:
- _entry = []
- for person in entry:
- for char in person:
- _entry.append(char)
- concatEntries.append(_entry)
- print(concatEntries)
- questionsSum = 0
- for entry in concatEntries:
- questionsSum += len(set(entry))
- print(questionsSum)
- # second part
- # sum all answers in each group that is equal to num of people
- alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
- numOfYesByAll = 0
- for entry in entries: # Check each group
- concatAnswer = [] # Concat all answers in group to count occurences of chars
- for answer in entry:
- for char in answer:
- concatAnswer.append(char)
- concatAnswer.sort() # Sort the string with all answers, because why not
- yesByAll = []
- numPeople = len(entry)
- print(f"Checking group of {numPeople} people, with answers:\n{concatAnswer}")
- for char in alphabet:
- if concatAnswer.count(char) == numPeople:
- print(f"'{char}' has correct num of occurrences: {numPeople}")
- yesByAll.append(char)
- numOfYesByAll += len(yesByAll)
- print(f"num of questions answered yes by all: {len(yesByAll)}")
- print(f"Current sum of questions to which everyone answered yes: {numOfYesByAll}")
- print()
- print(numOfYesByAll)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement