Skip to content

Instantly share code, notes, and snippets.

@alexxxmf
Last active October 16, 2016 10:10
Show Gist options
  • Save alexxxmf/91de3fc1c5e3fa53a02e35c75ea28345 to your computer and use it in GitHub Desktop.
Save alexxxmf/91de3fc1c5e3fa53a02e35c75ea28345 to your computer and use it in GitHub Desktop.
big_num = '7316717653133062491922511542828064444866452387493035890'
big_num_len = len(big_num)
list_of_products = []
def multiply_adjacents(adj_num):
product = 0
first_pos = True
for element in adj_num:
element = int(element)
if first_pos == True:
product = element
first_pos = False
else:
product = product * element
return product
def find_adjacents(big_num, length):
if isinstance(big_num, str) == False:
big_num = str(big_num)
list_of_products = []
big_num_len = len(big_num)
pos_limit = big_num_len - length
for element in range(0, pos_limit + 1):
adj_num = (big_num[element:(element+length)])
list_of_products.append( multiply_adjacents(adj_num) )
return sorted(list_of_products, reverse=True)[0]
def find_anagrams(list_of_words, word):
sliced_word = []
sliced_word += word
list_of_anagrams = []
for element in list_of_words:
sliced_element = []
sliced_element += element
if sorted(sliced_element) == sorted(sliced_word):
list_of_anagrams.append(element)
return list_of_anagrams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment