Last active
February 22, 2024 20:34
-
-
Save athursto/2a7751d39206f040a07fad23d518024d to your computer and use it in GitHub Desktop.
solution02.22.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""02.21.2024""" | |
""" | |
Given a string array, find the maximum product of word lengths where the words | |
don't share any letters. | |
""" | |
import itertools | |
list_input = ["fish","fear","boo","egg","cake","abcdef"] | |
def word_length_product(input): | |
comparisons = list(itertools.combinations(list_input, 2)) | |
no_match = [] | |
product = 0 | |
for item in range(len(comparisons)): | |
comparison1 = set(comparisons[item][0]) | |
comparison2 = set(comparisons[item][1]) | |
if comparison1.intersection(comparison2): | |
print(f"match between {comparisons[item][0]} and {comparisons[item][1]}") | |
if not comparison1.intersection(comparison2): | |
no_match.append(comparisons[item]) | |
product_holder = len(comparisons[item][0]) * len(comparisons[item][1]) | |
if product_holder > product: | |
product = product_holder | |
print(f"No match between {comparisons[item][0]} and {comparisons[item][1]}, new product is {product}") | |
longest = comparisons[item] | |
return product, longest | |
word_length_product(list_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment