rename function

This commit is contained in:
Daniel Mevec 2022-12-03 10:24:05 +01:00
parent dddaa2ebe7
commit 3634ba6b82

View file

@ -41,7 +41,7 @@ def compartments(rucksack:str):
l = len(t)//2 l = len(t)//2
return t[:l], t[l:] return t[:l], t[l:]
def compare(*comps:str) -> str: def find_common(*comps:str) -> str:
cs = [set(c) for c in comps] cs = [set(c) for c in comps]
return cs[0].intersection(*cs[1:]).pop() return cs[0].intersection(*cs[1:]).pop()
@ -61,7 +61,7 @@ CrZsJsPPZsGzwwsLwLmpwMDw"""
rucksacks = [compartments(line) for line in lines] rucksacks = [compartments(line) for line in lines]
print(sum([priority[compare(*rucksack)] for rucksack in rucksacks])) print(sum([priority[find_common(*rucksack)] for rucksack in rucksacks]))
""" """
As you finish identifying the misplaced items, the Elves come to you with another issue. As you finish identifying the misplaced items, the Elves come to you with another issue.
@ -95,5 +95,5 @@ Priorities for these items must still be found to organize the sticker attachmen
Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those item types? Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those item types?
""" """
groups = np.array(lines).reshape(-1,3) groups = np.array(lines).reshape(-1,3)
badges = [priority[compare(*group)] for group in groups] badges = [priority[find_common(*group)] for group in groups]
print(sum(badges)) print(sum(badges))