Skip to content

Commit

Permalink
Add part 1 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
gc0rreiab committed Dec 18, 2022
1 parent d2d040f commit 9b6f35a
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion day3_Rucksack-Reorganization/challenge.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
#Challange 3
import sys

class Rucksack:
def __init__ (self, items):
self.items = items
self.compartments1, self.compartments2 = items[:len(items)//2], items[len(items)//2:]
self.error = 0
self.priorities = 0

def findError(self):
e = list(set(self.compartments1) & set(self.compartments2))
self.error = e[0]
if self.error.isupper():
self.priorities = ord(self.error) - 38
else:
self.priorities = ord(self.error) - 96



file = open('input.txt', 'r')
lines = file.readlines()

total = 0

for line in lines:
line = line.rstrip('\n')
r = Rucksack(line)
r.findError()
total = total + r.priorities

#Part 1 result
print(total)

exit()



0 comments on commit 9b6f35a

Please sign in to comment.