We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
fromitertoolsimportpermutationsdefcalculate_product(item):x=(len(item)// 2) + (len(item) % 2)returnint(''.join(item[0:1]))*int(''.join(item[1:x]))defmain():max_number=int(input("Enter the maximum number: "))number=[str(x)forxinrange(1,max_number+1)]p_numbers=permutations(number)unique_products=set()foriteminp_numbers:product=calculate_product(item)ifproduct==int(''.join(item[x:]))andlen(item)>1:unique_products.add(int(''.join(item[x:])))print(sum(unique_products))if__name__=="__main__":main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #32: Pandigital products
You are viewing a single comment's thread. Return to all comments →