Last active
April 29, 2017 07:32
-
-
Save kFTY/5ac7d1c224ddb44aecec7c8a51aa2ba7 to your computer and use it in GitHub Desktop.
求乘积最大
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
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