虫食い算
id:selvaggio:20070421:1177177934より出題。
○○○ × ○○ ----------- ○○○零○ただし、零=0
さあ、Prologの出番だ。
?- use_module(library(bounds)). product(A,B,C,D,E,F,G,H,I) :- Digits = [A,B,C,D,E,F,G,H,I], Digits in 1..9, all_different(Digits), ABC = A*100+B*10+C, DE = D*10 + E, FGHOI= F*10000 + G*1000 + H*100 + I, ABC * DE #= FGHOI, label(Digits).
実行結果:
?- time(product(A,B,C,D,E,F,G,H,I)). % 13,074,620 inferences, 5.91 CPU in 7.03 seconds (84% CPU, 2212288 Lips) A = 9, B = 2, C = 7, D = 6, E = 3, F = 5, G = 8, H = 4, I = 1 ; No
まとめると、927*63=58401ですな。
というわけで、id:selvaggioはHACKER*4HACKER*3=ENERGYを解いとけ。