NISHIO Hirokazu[Translate]
虫食い算


10の階乗は高々400万なので全探索で余裕で解ける
python
from itertools import permutations for xs in permutations(range(10), 10): a, b, c, d, e, f, g, h, i, j = xs if a == 0 or c == 0 or f == 0: continue if ( a * 1000 + b * 100 + a * 10 + b + c * 100 + d * 10 + e == f * 10000 + g * 1000 + h * 100 + i * 10 + j ): print(xs)
output
(9, 3, 8, 6, 4, 1, 0, 2, 5, 7)


"Engineer's way of creating knowledge" the English version of my book is now available on [Engineer's way of creating knowledge]

(C)NISHIO Hirokazu / Converted from [Scrapbox] at [Edit]