-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdag3_deel1.py
28 lines (23 loc) · 1.03 KB
/
dag3_deel1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# make sure you can read from rucksack.txt
rucksack = open('rucksack.txt', 'r').readlines()
# remove the newlines
rucksack = [i.replace('\n', '') for i in rucksack]
# check the length of every item, split it in two (equal parts)
compartments = [[item[:(len(item) // 2)], item[(len(item) // 2):]] for item in rucksack]
# print(compartments)
# grab the letter that lives in the first and second compartment, put it in a string in a list
compartments = [''.join(set(duplicate for duplicate in item[0] if duplicate in item[1])) for item in compartments]
print(compartments)
# Return an integer representing the Unicode code point of that character(order func).
# Figure out the character integers
print(ord('a'))
print(ord('A'))
print(ord('z'))
print(ord('Z'))
# a=97, A=65, z=122, Z=90
# example: A: 65 % 64 - 26 = -25
# example: a: 97 % 64 - 32 = 1
def score(duplicate):
return ord(duplicate) % 64 - (32 if duplicate.islower() else -26)
# Add all the integers together to get the sum
print(sum([score(duplicate) for duplicate in compartments]))