Skip to content

Instantly share code, notes, and snippets.

@phlinhng
Created March 9, 2021 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phlinhng/9d92784d9171a4ddca60cc642d77048b to your computer and use it in GitHub Desktop.
Save phlinhng/9d92784d9171a4ddca60cc642d77048b to your computer and use it in GitHub Desktop.
# -*- 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