Created
March 9, 2021 07:13
-
-
Save phlinhng/9d92784d9171a4ddca60cc642d77048b 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
# -*- coding: utf-8 -*- | |
# 暴力美學 2.0 - 以空間換時間 | |
from itertools import permutations | |
candA, candB, candC = [], [], [] | |
for item in permutations(range(1,10)): | |
if(item[2] != 9): # 排除第3位是9的 | |
candA.append(item) | |
print("Candidates:",len(candA)) | |
for can in candA: | |
if((10*can[0]*can[2] + can[1] * can[2]) == (10*can[3] + can[4])): | |
candB.append(can) | |
print("Candidates:", len(candB)) | |
for can in candB: | |
if((10*can[3] + can[4] + 10*can[5] + can[6]) == (10*can[7] + can[8])): | |
candC.append(can) | |
print("Candidates:", len(candC)) | |
for can in candC: | |
print("Answer:", can) | |
# Answer: (1, 7, 4, 6, 8, 2, 5, 9, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment