我将进行数学竞赛,使写作方案能够解决问题。
该法典试图解决这一问题:
WHITE+WATER=PICNIC 每一封不同的字母代表数。 计算由事先知情同意委员会代表的人数。
No imports are allowed (tqdm was just a progress bar). What I tried is below. At the rate of which my computer goes, it is not fast enough for the times competition because it needs to range over 10 to the power of digits there is.
这一问题是否有明确的解决办法?
from tqdm import tqdm
def find_solution():
for W in tqdm(range(10)):
for H in tqdm(range(10), desc= H ):
for I in tqdm(range(10), desc= I ):
for T in tqdm(range(10)):
for E in tqdm(range(10)):
for A in (range(10)):
for R in (range(10)):
for P in (range(1, 10)): # P cannot be 0
for C in (range(10)):
for N in (range(10)):
white = W * 10000 + H * 1000 + I * 100 + T * 10 + E
water = W * 10000 + A * 1000 + T * 100 + E * 10 + R
picnic = P * 100000 + I * 10000 + C * 1000 + N * 100 + I * 10 + C
if white + water == picnic:
return { W : W, H : H, I : I, T : T, E : E, A : A, R : R, P : P, C : C, N : N}
return None
solution = find_solution()
if solution:
print("Solution found:")
print(solution)
else:
print("No solution found.")