Skip to content

Instantly share code, notes, and snippets.

@kFTY
Last active April 29, 2017 07:32
Show Gist options
  • Save kFTY/5ac7d1c224ddb44aecec7c8a51aa2ba7 to your computer and use it in GitHub Desktop.
Save kFTY/5ac7d1c224ddb44aecec7c8a51aa2ba7 to your computer and use it in GitHub Desktop.
求乘积最大
from itertools import permutations
def product(num):
strnum = str(num)
result = 0
for i in range(1, len(strnum)):
parta = strnum[:i]
partb = strnum[i:]
r = int(parta) * int(partb)
if r > result:
result = r
return (result)
def product_2(num):
result = 0
for p in permutations(str(num)):
mixnumber = "".join(p)
r = product(mixnumber)
if r > result:
result = r
return (result)
print (product(1234))
print (product(12345))
print (product_2(123456))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment