Skip to content

Commit

Permalink
Update 6.py
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismudith committed Jul 19, 2022
1 parent e9efdcc commit a99f9d1
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions 2020/6.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
# If you already have the data as an input use:
data = [] # Your Advent Input
# However, it is highly recommended to run this:
location = "C:\\Users\dagam\downloads\\input.txt" # Path of the input.txt provided from Advent Calendar
location = "t" # Path of the input.txt provided from Advent Calendar (Replace '\' → '\\')
try:
with open(location,'r') as f:
data = f.readlines()
f.close()
except:
pass
data = [o.rstrip('\n') for o in data]
if data[-1] == "'+":
del data[-1]
for o in data:
if o == "\n":
data[data.index(o)] = ' '
data = [o.replace('\n',';') for o in data]
if "'+" in data[-1]:
del data[-1]
data = (''.join(data)).split(' ') #Separating Groups

def get_count(group): # Part 1
group = list(map(str,(group.replace(';','')))) #Converting Each Group to A List
unique_values = list(set.union(*map(set, group)))
return len(unique_values)

def get_total_count(group): # Part 2
group = (''.join(group.replace(';',' ')))[:-1].split(' ') #Separating Values for Per Person
similar_values = list(set.intersection(*map(set, group)))
return len(similar_values)

def day6(part=1):
if part not in [1,2]:
part = 1
if part == 1:
value = 0
for group in data:
value += get_count(group)
return value
elif part == 2:
value = 0
for group in data:
value += get_total_count(group)
return value
print('Part 1: '+str(day6(part=1)))
print('Part 2: '+str(day6(part=2)))

0 comments on commit a99f9d1

Please sign in to comment.