Created
May 2, 2016 13:29
-
-
Save yuda110/f7016ef945d5dfb22903762f9890852f 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
#python3 | |
import re | |
from itertools import permutations | |
def get_permutation_list(): | |
permu_list = permutations('123456789', 9) | |
return permu_list | |
def get_pandigital_formula(permutation_list): | |
result_set = set() | |
for permu in permutation_list: | |
first_num = int(permu[0]) | |
second_num = int(permu[1]+permu[2]+permu[3]+permu[4]) | |
third_num = int(permu[5]+permu[6]+permu[7]+permu[8]) | |
if first_num*second_num == third_num: | |
result_set.add(third_num) | |
first_num = int(permu[0]+permu[1]) | |
second_num = int(permu[2]+permu[3]+permu[4]) | |
if first_num*second_num == third_num: | |
result_set.add(third_num) | |
return sum(result_set) | |
print(get_pandigital_formula(get_permutation_list())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment